Class: Hog::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/hog/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/hog/field.rb', line 4

def name
  @name
end

#optsObject (readonly)

Returns the value of attribute opts.



3
4
5
# File 'lib/hog/field.rb', line 3

def opts
  @opts
end

#typeObject (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_sObject



27
28
29
# File 'lib/hog/field.rb', line 27

def to_s
  "#{@name}:#{@type}"
end