Class: Reporter::Value

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#descriptionObject

Returns the value of attribute description.



13
14
15
# File 'lib/reporter/value.rb', line 13

def description
  @description
end

#field_aliasObject (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_nameObject (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_valueObject



16
17
18
# File 'lib/reporter/value.rb', line 16

def human_value
	@human_value || value
end

Returns the value of attribute source_link.



13
14
15
# File 'lib/reporter/value.rb', line 13

def source_link
  @source_link
end

#valueObject

Returns the value of attribute value.



13
14
15
# File 'lib/reporter/value.rb', line 13

def value
  @value
end

Instance Method Details

#as_percentageObject



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_sObject



20
21
22
# File 'lib/reporter/value.rb', line 20

def to_s
	human_value
end