Class: CSVImportable::TypeParser::PercentTypeParser
Instance Attribute Summary
#key, #required, #row, #value
Instance Method Summary
collapse
#initialize, #parse
Instance Method Details
#error_message ⇒ Object
10
11
12
|
# File 'lib/csv_importable/type_parser/percent_type_parser.rb', line 10
def error_message
"Invalid percent for column: #{key}. It should be a decimal between 0 and 1."
end
|
#outside_range ⇒ Object
14
15
16
|
# File 'lib/csv_importable/type_parser/percent_type_parser.rb', line 14
def outside_range
raise
end
|
#parse_percentage_sign ⇒ Object
18
19
20
|
# File 'lib/csv_importable/type_parser/percent_type_parser.rb', line 18
def parse_percentage_sign
value.to_f / 100.0
end
|
#parse_val ⇒ Object
3
4
5
6
7
8
|
# File 'lib/csv_importable/type_parser/percent_type_parser.rb', line 3
def parse_val
val = parse_percentage_sign if value.to_s.include?("%")
val = val.present? ? val : Float(value)
outside_range if val < 0 || val > 1
val
end
|