Class: Marbu::Models::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/marbu/models/mrf/base.rb

Direct Known Subclasses

Finalize, Map, Reduce

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ext_options = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
14
# File 'lib/marbu/models/mrf/base.rb', line 7

def initialize(ext_options = {})
  # keep_if weeds out nil arguments
  options         = default_options.merge( ext_options.keep_if{|k,v| v} )
  
  @keys           = options[:keys].map{ |k| Key.new(k) }
  @values         = options[:values].map{ |v| Value.new(v) }
  self.code       = options[:code]
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



5
6
7
# File 'lib/marbu/models/mrf/base.rb', line 5

def code
  @code
end

#keysObject

Returns the value of attribute keys.



4
5
6
# File 'lib/marbu/models/mrf/base.rb', line 4

def keys
  @keys
end

#valuesObject

Returns the value of attribute values.



4
5
6
# File 'lib/marbu/models/mrf/base.rb', line 4

def values
  @values
end

Instance Method Details

#add_key(name, function = nil) ⇒ Object



42
43
44
# File 'lib/marbu/models/mrf/base.rb', line 42

def add_key(name, function = nil)
  add(:key, name, function)
end

#add_value(name, function = nil) ⇒ Object



46
47
48
# File 'lib/marbu/models/mrf/base.rb', line 46

def add_value(name, function = nil)
  add(:value, name, function)
end

#blank?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/marbu/models/mrf/base.rb', line 54

def blank?
  !present?
end

#default_optionsObject



16
17
18
19
20
21
22
# File 'lib/marbu/models/mrf/base.rb', line 16

def default_options
  {
    :keys             => [],
    :values           => [],
    :code             => Code.new
  }
end

#present?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/marbu/models/mrf/base.rb', line 50

def present?
  @keys.present? || code.present?
end

#serializable_hashObject



34
35
36
37
38
39
40
# File 'lib/marbu/models/mrf/base.rb', line 34

def serializable_hash
  {
    :keys       => keys.collect(&:serializable_hash),
    :values     => values.collect(&:serializable_hash),
    :code       => code.serializable_hash
  }.delete_if{|k,v|v.blank?}
end