Class: NCUA::CreditUnion::Record
- Inherits:
-
Object
- Object
- NCUA::CreditUnion::Record
- Defined in:
- lib/ncua/credit_union/record.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
- .date_field(method_name, response_key = method_name) ⇒ Object
- .field(method_name, response_key = method_name, &munger) ⇒ Object
- .int_field(method_name, response_key = method_name) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Record
constructor
A new instance of Record.
Constructor Details
#initialize(attributes) ⇒ Record
Returns a new instance of Record.
4 5 6 7 |
# File 'lib/ncua/credit_union/record.rb', line 4 def initialize(attributes) @attributes = attributes @attributes.freeze end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/ncua/credit_union/record.rb', line 9 def attributes @attributes end |
Class Method Details
.date_field(method_name, response_key = method_name) ⇒ Object
27 28 29 30 31 |
# File 'lib/ncua/credit_union/record.rb', line 27 def self.date_field(method_name, response_key=method_name) field(method_name, response_key) { |value| Date.parse(value) } end |
.field(method_name, response_key = method_name, &munger) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ncua/credit_union/record.rb', line 11 def self.field(method_name, response_key=method_name, &munger) munger ||= lambda { |x| x } define_method(method_name) { if response_key.is_a? Symbol value = attributes[response_key] else value = attributes[response_key.to_s] end value && munger.call(value) } end |
.int_field(method_name, response_key = method_name) ⇒ Object
23 24 25 |
# File 'lib/ncua/credit_union/record.rb', line 23 def self.int_field(method_name, response_key=method_name) field(method_name, response_key, &:to_i) end |