Class: PathPrinter
- Inherits:
-
Object
- Object
- PathPrinter
- Defined in:
- lib/overpath/path_printer.rb
Overview
Generator for print key-value pairs
Class Method Summary collapse
- .str(data) ⇒ Object
- .str_del(data) ⇒ Object
- .str_mark(data, mark) ⇒ Object
- .string(data, is_list, escaped) ⇒ Object
- .string_from_key_and_value(key_value, escaped, mark, deletion) ⇒ Object
- .string_from_key_or_value(string, escaped, mark, deletion) ⇒ Object
- .string_from_key_value(o, escaped, mark, deletion) ⇒ Object
- .string_with_mark(data, is_list, escaped, mark) ⇒ Object
- .string_with_mark_deletion(data, is_list, escaped, mark, deletion) ⇒ Object
Class Method Details
.str(data) ⇒ Object
6 7 8 |
# File 'lib/overpath/path_printer.rb', line 6 def str(data) string(data, false, true) end |
.str_del(data) ⇒ Object
10 11 12 |
# File 'lib/overpath/path_printer.rb', line 10 def str_del(data) string_with_mark_deletion(data, false, true, '', true) end |
.str_mark(data, mark) ⇒ Object
14 15 16 |
# File 'lib/overpath/path_printer.rb', line 14 def str_mark(data, mark) string_with_mark(data, false, true, mark) end |
.string(data, is_list, escaped) ⇒ Object
18 19 20 |
# File 'lib/overpath/path_printer.rb', line 18 def string(data, is_list, escaped) string_with_mark(data, is_list, escaped, '') end |
.string_from_key_and_value(key_value, escaped, mark, deletion) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/overpath/path_printer.rb', line 48 def string_from_key_and_value(key_value, escaped, mark, deletion) value = (escaped ? Shellwords.escape(key_value[1]) : key_value[1]) mark = (mark == key_value[0] ? " \u{2764}" : '') deletion_mark = (deletion ? " \u{2716}" : '') "\"#{key_value[0]}\" => \"#{value}\"#{mark}#{deletion_mark}" end |
.string_from_key_or_value(string, escaped, mark, deletion) ⇒ Object
55 56 57 58 59 |
# File 'lib/overpath/path_printer.rb', line 55 def string_from_key_or_value(string, escaped, mark, deletion) string += (mark == string ? " \u{2764}" : '') string += (deletion ? " \u{2716}" : '') (escaped ? Shellwords.escape(string) : string) end |
.string_from_key_value(o, escaped, mark, deletion) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/overpath/path_printer.rb', line 38 def string_from_key_value(o, escaped, mark, deletion) line = nil if o.is_a?(Array) && o.size == 2 line = string_from_key_and_value(o, escaped, mark, deletion) elsif o.is_a?(String) line = string_from_key_or_value(o, escaped, mark, deletion) end line end |
.string_with_mark(data, is_list, escaped, mark) ⇒ Object
22 23 24 |
# File 'lib/overpath/path_printer.rb', line 22 def string_with_mark(data, is_list, escaped, mark) string_with_mark_deletion(data, is_list, escaped, mark, false) end |
.string_with_mark_deletion(data, is_list, escaped, mark, deletion) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/overpath/path_printer.rb', line 26 def string_with_mark_deletion(data, is_list, escaped, mark, deletion) output = [] if is_list data.each do |o| output << string_from_key_value(o, escaped, mark, deletion) end else output << string_from_key_value(data, escaped, mark, deletion) end output end |