Coder Social home page Coder Social logo

flat's People

Contributors

dependabot-preview[bot] avatar fascox avatar melriffe avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

flat's Issues

Unable to add instance method

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.

voter_file.rb

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

test script

[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'

Restructure and namespace functionality

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.