Class: IERail::IERailGet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, array_name, object_name) ⇒ IERailGet

Returns a new instance of IERailGet.



19
20
21
22
23
# File 'lib/ierail.rb', line 19

def initialize(url, array_name, object_name)
  @ws_url = URI.encode(url)
  @ws_array_name = array_name.downcase
  @ws_object_name = object_name.downcase
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



17
18
19
# File 'lib/ierail.rb', line 17

def result
  @result
end

Instance Method Details

#characters(string) ⇒ Object



37
38
39
40
# File 'lib/ierail.rb', line 37

def characters string
  string.strip!
  @result.last[@current] << string unless string.empty?
end

#end_element(name) ⇒ Object



54
55
56
57
58
59
# File 'lib/ierail.rb', line 54

def end_element name
  if @current && @result.last[@current].empty?
    @result.last.delete(@current)
  end
  @current = nil
end

#responseObject



25
26
27
28
29
30
31
# File 'lib/ierail.rb', line 25

def response
  unless @result
    parser = Nokogiri::XML::SAX::Parser.new(self)
    parser.parse(RestClient.get(URL + "/" + @ws_url))
  end
  @result
end

#start_documentObject



33
34
35
# File 'lib/ierail.rb', line 33

def start_document 
  @result = []
end

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



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ierail.rb', line 42

def start_element name, attrs = []
  case name.downcase
    when @ws_object_name 
      @result << Hash.new
    when @ws_array_name
      ;
    else
      @current = name          
      @result.last[@current] = ""
  end
end