Class: Reporter::Value
- Inherits:
-
Object
- Object
- Reporter::Value
- Defined in:
- lib/reporter/value.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#field_alias ⇒ Object
readonly
Returns the value of attribute field_alias.
-
#field_human_name ⇒ Object
readonly
Returns the value of attribute field_human_name.
- #human_value ⇒ Object
-
#source_link ⇒ Object
Returns the value of attribute source_link.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #as_percentage ⇒ Object
-
#initialize(field_alias, field_human_name, value, human_value, description, source_link) ⇒ Value
constructor
A new instance of Value.
- #round(precision = 2) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(field_alias, field_human_name, value, human_value, description, source_link) ⇒ Value
Returns a new instance of Value.
3 4 5 6 7 8 9 10 |
# File 'lib/reporter/value.rb', line 3 def initialize(field_alias, field_human_name, value, human_value, description, source_link) @field_alias = field_alias @field_human_name = field_human_name || field_alias @value = value @human_value = human_value @description = description @source_link = source_link end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
13 14 15 |
# File 'lib/reporter/value.rb', line 13 def description @description end |
#field_alias ⇒ Object (readonly)
Returns the value of attribute field_alias.
12 13 14 |
# File 'lib/reporter/value.rb', line 12 def field_alias @field_alias end |
#field_human_name ⇒ Object (readonly)
Returns the value of attribute field_human_name.
12 13 14 |
# File 'lib/reporter/value.rb', line 12 def field_human_name @field_human_name end |
#human_value ⇒ Object
16 17 18 |
# File 'lib/reporter/value.rb', line 16 def human_value @human_value || value end |
#source_link ⇒ Object
Returns the value of attribute source_link.
13 14 15 |
# File 'lib/reporter/value.rb', line 13 def source_link @source_link end |
#value ⇒ Object
Returns the value of attribute value.
13 14 15 |
# File 'lib/reporter/value.rb', line 13 def value @value end |
Instance Method Details
#as_percentage ⇒ Object
24 25 26 27 28 |
# File 'lib/reporter/value.rb', line 24 def as_percentage if @value.is_a? Numeric "%.2f %%" % (@value * 100.0) end end |
#round(precision = 2) ⇒ Object
30 31 32 33 34 |
# File 'lib/reporter/value.rb', line 30 def round(precision = 2) if @value.is_a? Numeric "%.#{precision}f" % @value end end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/reporter/value.rb', line 20 def to_s human_value end |