Class: Zoro::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/zoro/record.rb

Direct Known Subclasses

Account, Lead

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zoho_module = self.class.name.split("::").last << "s") ⇒ Record

Returns a new instance of Record.



5
6
7
8
# File 'lib/zoro/record.rb', line 5

def initialize(zoho_module= self.class.name.split("::").last << "s")
  @zoho_module = zoho_module
  @fields = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/zoro/record.rb', line 33

def method_missing(name, *args, &block)
  property_name = Zoro::FieldName.make_field(name.to_s)

  assignment = name.to_s.match(/=/)
  if assignment
    set_field property_name, args[0]
  else
    get_field property_name
  end
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



3
4
5
# File 'lib/zoro/record.rb', line 3

def fields
  @fields
end

#zoho_moduleObject (readonly)

Returns the value of attribute zoho_module.



3
4
5
# File 'lib/zoro/record.rb', line 3

def zoho_module
  @zoho_module
end

Instance Method Details

#apiObject



14
15
16
# File 'lib/zoro/record.rb', line 14

def api
  @api ||= Zoro::Api.new
end

#api=(api) ⇒ Object



10
11
12
# File 'lib/zoro/record.rb', line 10

def api=(api)
  @api = api
end

#save!Object



18
19
20
# File 'lib/zoro/record.rb', line 18

def save!
  api.insert_records(self)
end

#to_xmlObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/zoro/record.rb', line 22

def to_xml
  xml_map = Hash.new
  xml_map['row'] = {
    'no' => '1',
    'FL' => @fields.map do |k, v|
      { 'val' => k, 'content' => v}
    end
  }
  XmlSimple.xml_out(xml_map, :RootName => @zoho_module)
end