Class: ASF::Podling

Inherits:
Object
  • Object
show all
Extended by:
Enumerable
Includes:
Enumerable
Defined in:
lib/whimsy/asf/podlings.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Podling

create a podling from a Nokogiri node built from podlings.xml



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/whimsy/asf/podlings.rb', line 20

def initialize(node)
  @name = node['name']
  @resource = node['resource']
  @status = node['status']
  @enddate = node['enddate']
  @startdate = node['startdate']
  @description = node.at('description').text
  @mentors = node.search('mentor').map {|mentor| mentor['username']}
  @champion = node.at('champion')['availid'] if node.at('champion')

  @reporting = node.at('reporting')
end

Instance Attribute Details

#championObject

Returns the value of attribute champion.



8
9
10
# File 'lib/whimsy/asf/podlings.rb', line 8

def champion
  @champion
end

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'lib/whimsy/asf/podlings.rb', line 8

def description
  @description
end

#mentorsObject

Returns the value of attribute mentors.



8
9
10
# File 'lib/whimsy/asf/podlings.rb', line 8

def mentors
  @mentors
end

#nameObject

map resource to name



34
35
36
# File 'lib/whimsy/asf/podlings.rb', line 34

def name
  @name
end

#reportingObject

lazy evaluation of reporting



67
68
69
# File 'lib/whimsy/asf/podlings.rb', line 67

def reporting
  @reporting
end

#statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/whimsy/asf/podlings.rb', line 8

def status
  @status
end

Class Method Details

.each(&block) ⇒ Object

provide a list of podling names and descriptions



119
120
121
# File 'lib/whimsy/asf/podlings.rb', line 119

def self.each(&block)
  list.each {|podling| block.call podling.name, podling}
end

.find(name) ⇒ Object

find a podling by name



102
103
104
# File 'lib/whimsy/asf/podlings.rb', line 102

def self.find(name)
  list.find {|podling| podling.name == name}
end

.listObject

list of podlings



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/whimsy/asf/podlings.rb', line 86

def self.list
  incubator_content = ASF::SVN['asf/incubator/public/trunk/content']
  podlings_xml = "#{incubator_content}/podlings.xml"

  if @mtime != File.mtime(podlings_xml)
    @list = []
    podlings = Nokogiri::XML(File.read(podlings_xml))
    podlings.search('podling').map do |node|
      @list << new(node)
    end
  end

  @list
end

.to_hObject

return the entire list as a hash



114
115
116
# File 'lib/whimsy/asf/podlings.rb', line 114

def self.to_h
  Hash[self.to_a]
end

Instance Method Details

#[](name) ⇒ Object

allow attributes to be accessed as hash



124
125
126
# File 'lib/whimsy/asf/podlings.rb', line 124

def [](name)
  return self.send name if self.respond_to? name
end

#display_nameObject

map name to display_name



44
45
46
# File 'lib/whimsy/asf/podlings.rb', line 44

def display_name
  @name || @resource
end

#enddateObject

parse enddate



58
59
60
61
62
63
64
# File 'lib/whimsy/asf/podlings.rb', line 58

def enddate
  return unless @enddate
  return Date.parse("#@enddate-15") if @enddate.length < 8
  Date.parse(@enddate)
rescue ArgumentError
  nil
end

#idObject

also map resource to id



39
40
41
# File 'lib/whimsy/asf/podlings.rb', line 39

def id
  @resource
end

#quarterObject

three consecutive months, starting with this one



11
12
13
14
15
16
17
# File 'lib/whimsy/asf/podlings.rb', line 11

def quarter
  [
    Date.today.strftime('%B'),
    Date.today.next_month.strftime('%B'),
    Date.today.next_month.next_month.strftime('%B')
  ]
end

#startdateObject

parse startdate



49
50
51
52
53
54
55
# File 'lib/whimsy/asf/podlings.rb', line 49

def startdate
  return unless @startdate
  return Date.parse("#@startdate-15") if @startdate.length < 8
  Date.parse(@startdate)
rescue ArgumentError
  nil
end