Class: WAZ::Tables::EdmTypeHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/waz/tables/edm_type_helper.rb

Class Method Summary collapse

Class Method Details

.parse_from(item) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/waz/tables/edm_type_helper.rb', line 5

def parse_from(item)
  return nil if !item.attributes['m:null'].nil? and item.attributes['m:null'] == 'true'
  case item.attributes['m:type']
    when 'Edm.Int16', 'Edm.Int32', 'Edm.Int64'
      item.text.to_i
    when 'Edm.Single', 'Edm.Double'
      item.text.to_f
    when 'Edm.Boolean'
      item.text == 'true'
    when 'Edm.DateTime'
      Time.parse(item.text)
    when 'Edm.Binary'
      StringIO.new(Base64.decode64(item.text))
    else
      item.text
  end
end

.parse_to(item) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/waz/tables/edm_type_helper.rb', line 23

def parse_to(item)
  case item.class.name
    when 'String'
      [item, 'Edm.String']
    when 'Fixnum'
      [item, 'Edm.Int32']
    when 'Float'
      [item, 'Edm.Double']
    when 'TrueClass', 'FalseClass'          
      [item, 'Edm.Boolean']
    when 'Time'
      [item.iso8601, 'Edm.DateTime']
    when 'File', 'StringIO'
      item.pos = 0
      [Base64.encode64(item.read), 'Edm.Binary']
    else
      [item, 'Edm.String']
  end
end