Class: AliasList
- Inherits:
-
Object
- Object
- AliasList
- Defined in:
- lib/alias_metrics/alias_list.rb
Instance Attribute Summary collapse
-
#alias_hash ⇒ Object
Returns the value of attribute alias_hash.
Class Method Summary collapse
Instance Method Summary collapse
-
#applied_alias(command) ⇒ Object
NOTE: Since #command >> #alias, this process do fastly.
-
#expand_command(command) ⇒ Object
NOTE: Since #command >> #alias, this process do fastly.
-
#shortenable?(command) ⇒ Boolean
NOTE: Since #command >> #alias, this process do fastly.
- #shortenable_alias(command) ⇒ Object
Instance Attribute Details
#alias_hash ⇒ Object
Returns the value of attribute alias_hash.
2 3 4 |
# File 'lib/alias_metrics/alias_list.rb', line 2 def alias_hash @alias_hash end |
Class Method Details
.load_from_lines(lines) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/alias_metrics/alias_list.rb', line 4 def self.load_from_lines(lines) alias_hash = Hash::new lines.each do |line| key, value = separate_key_value_from_alias_line(line) alias_hash[key] = value end AliasList.new(alias_hash) end |
.load_from_stdin ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/alias_metrics/alias_list.rb', line 13 def self.load_from_stdin alias_hash = Hash::new STDIN.each do |line| line.chomp! key, value = separate_key_value_from_alias_line(line) alias_hash[key] = value end AliasList.new(alias_hash) end |
Instance Method Details
#applied_alias(command) ⇒ Object
NOTE: Since #command >> #alias, this process do fastly
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/alias_metrics/alias_list.rb', line 34 def applied_alias(command) ret = [] @alias_hash.each_pair do |key, value| if used_subcommand?(command, key) command = command.sub(key, value) ret << [key, value] end end ret end |
#expand_command(command) ⇒ Object
NOTE: Since #command >> #alias, this process do fastly
24 25 26 27 28 29 30 31 |
# File 'lib/alias_metrics/alias_list.rb', line 24 def (command) @alias_hash.each_pair do |key, value| if used_subcommand?(command, key) command = command.sub(key, value) end end command end |
#shortenable?(command) ⇒ Boolean
NOTE: Since #command >> #alias, this process do fastly
46 47 48 49 50 51 52 53 |
# File 'lib/alias_metrics/alias_list.rb', line 46 def shortenable?(command) @alias_hash.values.each do |value| if used_subcommand?(command, value) return true end end false end |
#shortenable_alias(command) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/alias_metrics/alias_list.rb', line 55 def shortenable_alias(command) ret = [] @alias_hash.each_pair do |key, value| if used_subcommand?(command, value) ret << [key, value] end end ret end |