Class: ActiveApi::SimpleType

Inherits:
Object
  • Object
show all
Includes:
Builder
Defined in:
lib/active_api/simple_type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Builder

#build_xml

Constructor Details

#initialize(text, options) ⇒ SimpleType

Returns a new instance of SimpleType.



81
82
83
84
85
# File 'lib/active_api/simple_type.rb', line 81

def initialize(text, options)
  @text   = text
  @node   = options[:node]
  @format = options[:format]
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



79
80
81
# File 'lib/active_api/simple_type.rb', line 79

def format
  @format
end

#nodeObject (readonly)

Returns the value of attribute node.



79
80
81
# File 'lib/active_api/simple_type.rb', line 79

def node
  @node
end

#textObject (readonly)

Returns the value of attribute text.



79
80
81
# File 'lib/active_api/simple_type.rb', line 79

def text
  @text
end

Class Method Details

.default_format_procObject



63
64
65
# File 'lib/active_api/simple_type.rb', line 63

def default_format_proc
  proc { |value| value }
end

.format_procsObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/active_api/simple_type.rb', line 67

def format_procs
  {
    :normalized_string => proc {|value| value },
    :token =>             proc {|value| value },
    :date_time =>         proc {|value| value.strftime("%Y-%m-%dT%H:%M:%S%Z") },
    :time =>              proc {|value| value.strftime("%H:%M:%S%Z") },
    :date =>              proc {|value| value.strftime("%Y-%m-%d") },
    :any_uri =>           proc {|value| URI.escape(value) }
  }
end

.formatsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/active_api/simple_type.rb', line 6

def formats
  standard_names = [
    :base64Binary,
    :boolean,
    :date,
    :dateTime,
    :dateTimeStamp,
    :decimal,
    :integer,
    :long,
    :int,
    :short,
    :byte,
    :nonNegativeInteger,
    :positiveInteger,
    :unsignedLong,
    :unsignedInt,
    :unsignedShort,
    :unsignedByte,
    :nonPositiveInteger,
    :negativeInteger,
    :double,
    :duration,
    :dayTimeDuration,
    :yearMonthDuration,
    :float,
    :gDay,
    :gMonth,
    :gMonthDay,
    :gYear,
    :gYearMonth,
    :hexBinary,
    :precisionDecimal,
    :string,
    :normalizedString,
    :token,
    :language,
    :time
  ].map do |format|
    {format.to_s.underscore.to_sym => format}
  end

  custom_names = [
    {:any_uri => :anyURI},
    {:notation => :NOTATION},
    {:qname => :QName},
    {:name => :Name},
    {:nc_name => :NCName},
    {:entity => :ENTITY},
    {:id => :ID},
    {:idref => :IDREF},
    {:nmtoken => :NMTOKEN},
  ]

  standard_names + custom_names
end

Instance Method Details

#append(hash) ⇒ Object



87
88
89
# File 'lib/active_api/simple_type.rb', line 87

def append(hash)
  hash[node] = formatted_text
end