Sha256: 5515d2227cbef787c55a32c80398abfdd6e504c20c54355c1bf00ec3070f7bdc

Contents?: true

Size: 662 Bytes

Versions: 2

Compression:

Stored size: 662 Bytes

Contents

class MyParser
  include JsonParser

  json_parse :id
  json_parse :name, :age, path: :person
  json_parse :total_money, full_path: 'accounts.balance', after: :sum,
                          cached: true, type: :money_float
  json_parse :total_owed, full_path: 'loans.value', after: :sum,
                          cached: true, type: :money_float

  attr_reader :json

  def initialize(json = {})
    @json = json
  end

  private

  def sum(balances)
    balances.sum if balances
  end

  models = File.expand_path("spec/support/models/my_parser/*.rb")
  Dir[models].each do |file|
    autoload file.gsub(/.*\/(.*)\..*/, '\1').camelize.to_sym, file
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
json_parser-1.3.1 spec/support/models/my_parser.rb
json_parser-1.3.0 spec/support/models/my_parser.rb