Class: Bishl::Parser

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

Instance Method Summary collapse

Instance Method Details

#parse_schedule(opt = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/parser.rb', line 34

def parse_schedule(opt={})
  begin
    url = ParamsBuilder.build_link(opt)
    xml = fetch(url,"schedule")
    data = []
    xml.xpath("//game").each do |line|
      g = Game.new
      line.children.each do |child|
        #puts child.text if child.name.match(/gameid/)
        if child.name.match(/startdate/)
          g.send("#{child.name}=", Chronic.parse(child.text))
        else
          g.send("#{child.name}=", child.text) if g.respond_to?(child.name.to_sym)
        end
      end
      data << g
    end
    return data
  rescue => e
    raise e
  end
end

#parse_standings(opt = {}) ⇒ Object

opt => => “2010”, :cs => “LLA” Returns an array of schedule_lines



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
# File 'lib/parser.rb', line 7

def parse_standings(opt={})
  begin
    url = ParamsBuilder.build_link(opt)
    xml = fetch(url,"standings")
    data = []
    xml.xpath("//team").each do |inf|
    c = ScheduleLine.new

    inf.children.each do |child|
      if(child.is_a?(Nokogiri::XML::Element))
        #puts "#{child.name} - #{child.text}"
        #c.create_line({:name => child.name, :text => child.text})
        c.send("create_#{child.name}", child.text)

      end

      #c.send("#{child.name.to_s}=",child['data'])
    end
    data << c

    end
    return data
  rescue => e
    raise e
  end
end