Class: RacePerformanceStatus
- Inherits:
-
Object
- Object
- RacePerformanceStatus
- Defined in:
- app/models/race_performance_status.rb
Constant Summary collapse
- @@statuses =
[ RacePerformanceStatus.new(:id => 0, :name => '?', :aliases => ['unknown'] ), RacePerformanceStatus.new(:id => 10, :name => 'Ret', :aliases => ['retired', 'r', 'ret']), RacePerformanceStatus.new(:id => 20, :name => 'DNF', :aliases => ['did not finish', 'x', 'dnf']), RacePerformanceStatus.new(:id => 30, :name => 'TO', :aliases => ['timed out', 't', 'to']), RacePerformanceStatus.new(:id => 50, :name => 'Dsq', :aliases => ['disqualified', 'disq', 'd', 'dsq']), RacePerformanceStatus.new(:id => 100, :name => 'Finished') ]
Instance Attribute Summary collapse
-
#aliases ⇒ Object
Returns the value of attribute aliases.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .[](value = "") ⇒ Object
- .find(id = 0) ⇒ Object
- .find_all ⇒ Object
- .from_pos_or_time(pos = "", time = "") ⇒ Object
- .from_time(time = "") ⇒ Object
Instance Method Summary collapse
- #has_alias?(value) ⇒ Boolean
-
#initialize(options = {}) ⇒ RacePerformanceStatus
constructor
A new instance of RacePerformanceStatus.
- #symbol ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ RacePerformanceStatus
Returns a new instance of RacePerformanceStatus.
4 5 6 7 8 |
# File 'app/models/race_performance_status.rb', line 4 def initialize( = {}) = .symbolize_keys @id, @name = [:id], [:name] @aliases = ([:aliases] || []).collect {|name| name.to_s.downcase.intern} end |
Instance Attribute Details
#aliases ⇒ Object
Returns the value of attribute aliases.
2 3 4 |
# File 'app/models/race_performance_status.rb', line 2 def aliases @aliases end |
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'app/models/race_performance_status.rb', line 2 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'app/models/race_performance_status.rb', line 2 def name @name end |
Class Method Details
.[](value = "") ⇒ Object
26 27 28 29 |
# File 'app/models/race_performance_status.rb', line 26 def self.[](value="") value = "?" if value.blank? || value == 0 @@statuses.find { |status| status.symbol == value.to_s.downcase.intern || status.has_alias?(value) } end |
.find(id = 0) ⇒ Object
31 32 33 |
# File 'app/models/race_performance_status.rb', line 31 def self.find(id=0) @@statuses.find { |status| status.id.to_s == id.to_s } end |
.find_all ⇒ Object
35 36 37 |
# File 'app/models/race_performance_status.rb', line 35 def self.find_all @@statuses.dup end |
.from_pos_or_time(pos = "", time = "") ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'app/models/race_performance_status.rb', line 39 def self.from_pos_or_time(pos="",time="") if self[pos] self[pos] elsif pos.looks_like_number? self["Finished"] else self.from_time(time) end end |
.from_time(time = "") ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'app/models/race_performance_status.rb', line 49 def self.from_time(time="") if time.seconds > 0 # String.seconds returns 0 for a string that doesn't parse. See DurationExtensions for method. self["Finished"] elsif self[time] self[time] else self["?"] end end |
Instance Method Details
#has_alias?(value) ⇒ Boolean
14 15 16 |
# File 'app/models/race_performance_status.rb', line 14 def has_alias?(value) @aliases.include?(value.to_s.downcase.intern) end |
#symbol ⇒ Object
10 11 12 |
# File 'app/models/race_performance_status.rb', line 10 def symbol @name.to_s.downcase.intern end |
#to_i ⇒ Object
22 23 24 |
# File 'app/models/race_performance_status.rb', line 22 def to_i @id end |
#to_s ⇒ Object
18 19 20 |
# File 'app/models/race_performance_status.rb', line 18 def to_s @name end |