Class: Socialcastr::SAX::ActiveResource

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/socialcastr/sax/active_resource.rb

Constant Summary collapse

HASH =
"hash"
ARRAY =
"array"
INTEGER =
"integer"
BOOLEAN =
"boolean"
STRING =
"string"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeActiveResource

Returns a new instance of ActiveResource.



28
29
30
31
32
# File 'lib/socialcastr/sax/active_resource.rb', line 28

def initialize
  @types = []
  @values = []
  @data= nil
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



21
22
23
# File 'lib/socialcastr/sax/active_resource.rb', line 21

def data
  @data
end

Instance Method Details

#cdata_block(s) ⇒ Object



34
35
36
# File 'lib/socialcastr/sax/active_resource.rb', line 34

def cdata_block(s)
  characters(s)
end

#characters(string) ⇒ Object



45
46
47
48
# File 'lib/socialcastr/sax/active_resource.rb', line 45

def characters string
  return if nil_element? || (string.all_spaces? && (container_type != STRING || container_value.nil?))
  update_string_element(string)
end

#end_element(name) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/socialcastr/sax/active_resource.rb', line 50

def end_element name
  return end_nil_element if nil_element?

  (value, type) = pop_element
  case type
  when HASH
    return nil unless value
    element = element_class(name).from_hash(value)
  when INTEGER
    element = value.to_i
  when BOOLEAN
    element = value == "true" ? true : false
  when ARRAY
    element = value || []
  else
    element = value
  end

  if container_type
    add_to_container(name, element)
  else # Root Node
    self.data = element
  end
end

#start_element(name, attrs = []) ⇒ Object



38
39
40
41
42
43
# File 'lib/socialcastr/sax/active_resource.rb', line 38

def start_element name, attrs = []
  return nil_element! if unsupported?(name)
  type = parse_attrs_and_get_type(attrs)
  return nil_element! if type.nil?
  push_element(type)
end