Module: Parsed::Parseable::ClassMethods

Defined in:
lib/parsed/parseable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parseable_fieldsObject

Returns the value of attribute parseable_fields.



17
18
19
# File 'lib/parsed/parseable.rb', line 17

def parseable_fields
  @parseable_fields
end

#parseable_hashObject

Returns the value of attribute parseable_hash.



17
18
19
# File 'lib/parsed/parseable.rb', line 17

def parseable_hash
  @parseable_hash
end

#parserObject

Returns the value of attribute parser.



17
18
19
# File 'lib/parsed/parseable.rb', line 17

def parser
  @parser
end

Instance Method Details

#parse(data, parser = ParsesJson) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/parsed/parseable.rb', line 21

def parse(data, parser = ParsesJson)
  @parser = parser
  @parseable_hash = parser.parse(data)

  instance = new
  parse_fields(instance)
  instance
end

#parses(*attributes) ⇒ Object

Public: Registers attributes that are to be parsed.

attributes - The fields to be parsed

Examples

class Foo
  include Parsed::Parseable
  attr_accessor :foo, :bar, :baz
  parsed :foo, :bar, :baz
end


42
43
44
45
46
# File 'lib/parsed/parseable.rb', line 42

def parses(*attributes)
  attributes.each do |attributes|
    parseable_fields << attributes
  end
end