juicyparts / flat Goto Github PK
View Code? Open in Web Editor NEWLibrary to make processing Flat Flies as easy as CSV files.
Home Page: http://juicyparts.com/flat/
License: Other
Library to make processing Flat Flies as easy as CSV files.
Home Page: http://juicyparts.com/flat/
License: Other
I'm trying to test this library by putting the content out as a hash. But when I try it getting a no method error for the error I've defined.
class VoterFile < Flat::File
add_field :county_code, width: 3, filter: :compact
add_field :precinct, width: 10, filter: :compact
add_field :vuid, width: 10, filter: :compact
add_field :last_name, width: 50, filter: :compact
add_field :first_name, width: 50, filter: :compact
add_field :middle_name, width: 50, filter: :compact
add_field :former_last_name, width: 50, filter: :compact
add_field :suffix, width: 4, filter: :compact
add_field :gender, width: 1, filter: :compact
add_field :dob, width: 8, filter: :compact
add_field :perm_house_number, width: 9, filter: :compact
add_field :perm_desinator, width: 12, filter: :compact
add_field :perm_directional_prefix, width: 2, filter: :compact
add_field :perm_street_name, width: 50, filter: :compact
add_field :perm_street_type, width: 12, filter: :compact
add_field :perm_directional_suffix, width: 2
add_field :perm_unit_number, width: 12, filter: :compact
add_field :perm_unit_type, width: 12, filter: :compact
add_field :perm_city, width: 50, filter: :compact
add_field :perm_zipcode, width: 9, filter: :compact
add_field :mailing_address_1, width: 110, filter: :compact
add_field :mailing_address_1, width: 50, filter: :compact
add_field :mailing_city, width: 50, filter: :compact
add_field :mailing_state, width: 20, filter: :compact
add_field :mailing_zipcode, width: 20, filter: :compact
add_field :edr, width: 8, filter: :compact
add_field :status_code, width: 1, filter: :compact
add_field :hispanic_surname_flag, width: 1, filter: :compact
add_field :election_date, width: 8, filter: :compact
add_field :election_type, width: 2, filter: :compact
add_field :election_party, width: 3, filter: :compact
add_field :election_voting_method, width: 6, filter: :compact
def self.compact(v)
v.squish
end
def to_hash
self.instance_variables.each_with_object({}) { |var, hash| hash[var.to_s.delete("@")] = self.instance_variable_get(var) }
end
end
[4] pry(main)> file.each_record(open('./data_files/voter_records/TX/voters.txt')) do |record|
[4] pry(main)* puts record.to_hash
[4] pry(main)* end
/Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-0.12.2/lib/pry/exceptions.rb:28: warning: $SAFE will become a normal global variable in Ruby 3.0
Errors::FlatFileError: Unknown method: to_hash
from /Users/antarr/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/flat-0.1.5/lib/flat/record.rb:93:in `method_missing'
I ran into a situation where a codebase using 'flat' also defined an Errors
module. The gem effectively hid their module.
Therefore I need to make sure everything in the gem is namespaced to the Flat
module.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.