Class: Ztodo::Converter
- Inherits:
-
Object
- Object
- Ztodo::Converter
- Defined in:
- lib/ztodo/converter.rb
Overview
Class for converting task hashes to strings and vice versa
Instance Method Summary collapse
- #colored_priority(int_val) ⇒ Object
-
#hash_to_str(hash) ⇒ Object
Convert hash representation of task to string.
-
#str_to_hash(str) ⇒ Object
Convert string representation of task to hash.
Instance Method Details
#colored_priority(int_val) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ztodo/converter.rb', line 27 def colored_priority int_val require 'colorize' if int_val == Ztodo::Project::LOW 'low'.green elsif int_val == Ztodo::Project::NORMAL 'normal'.yellow elsif int_val == Ztodo::Project::HIGH 'high'.red else raise Exception.new('Priority should be -1, 0 or 1. Given: '+int_val) end end |
#hash_to_str(hash) ⇒ Object
Convert hash representation of task to string
18 19 20 21 22 23 24 25 |
# File 'lib/ztodo/converter.rb', line 18 def hash_to_str hash out = '' out += hash[:key].to_s+" # unique identifier of task\n" out += format_priority(hash[:priority])+" # priority: 'low', 'normal' or 'high'\n" out += (hash[:done] ? 'done' : 'undone' )+" # task completeness: 'done' or 'undone'\n" out += hash[:description].to_s out end |
#str_to_hash(str) ⇒ Object
Convert string representation of task to hash
7 8 9 10 11 12 13 14 15 |
# File 'lib/ztodo/converter.rb', line 7 def str_to_hash str out = {} data = str.split("\n") out[:key] = parse_key_line data[0] out[:priority] = parse_priority_line data[1] out[:done] = parse_completeness_line data[2] out[:description] = extract_description data.clone out end |