Class: Hog::Field
- Inherits:
-
Object
- Object
- Hog::Field
- Defined in:
- lib/hog/field.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #get(hash) ⇒ Object
-
#initialize(type, name, opts = {}) ⇒ Field
constructor
A new instance of Field.
- #to_s ⇒ Object
Constructor Details
#initialize(type, name, opts = {}) ⇒ Field
Returns a new instance of Field.
7 8 9 10 11 12 |
# File 'lib/hog/field.rb', line 7 def initialize(type, name, opts={}) @name = name @type = type @opts = opts opts[:path] ||= name.to_s end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/hog/field.rb', line 4 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
3 4 5 |
# File 'lib/hog/field.rb', line 3 def opts @opts end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/hog/field.rb', line 5 def type @type end |
Instance Method Details
#get(hash) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hog/field.rb', line 14 def get(hash) val = nil if opts[:value] val = opts[:value] elsif opts[:json] lkval = lookup(opts[:json],hash) || opts[:default] val = JSON.dump(lkval) else val = lookup(opts[:path], hash) end get_value(val) end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/hog/field.rb', line 27 def to_s "#{@name}:#{@type}" end |