Class: AliasMetrics::AliasList
- Inherits:
-
Object
- Object
- AliasMetrics::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
- .load(io, alias_line_parser) ⇒ Object
- .load_from_file(file, alias_line_parser = AliasLineParser::Zsh.new) ⇒ Object
- .load_from_lines(lines, alias_line_parser = AliasLineParser::Zsh.new) ⇒ Object
- .load_from_stdin(alias_line_parser = AliasLineParser::Zsh.new) ⇒ Object
Instance Method Summary collapse
- #appliable_alias(command) ⇒ Object
-
#expand_command(command) ⇒ Object
NOTE: Since #command >> #alias, this process do fastly.
- #shorten_command(command) ⇒ Object
-
#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.
3 4 5 |
# File 'lib/alias_metrics/alias_list.rb', line 3 def alias_hash @alias_hash end |
Class Method Details
.load(io, alias_line_parser) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/alias_metrics/alias_list.rb', line 6 def load(io, alias_line_parser) alias_hash = Hash::new io.each do |line| line.chomp! alias_, real = alias_line_parser.parse(line) alias_hash[alias_] = real end AliasList.new(alias_hash) end |
.load_from_file(file, alias_line_parser = AliasLineParser::Zsh.new) ⇒ Object
29 30 31 32 33 |
# File 'lib/alias_metrics/alias_list.rb', line 29 def load_from_file(file, alias_line_parser=AliasLineParser::Zsh.new) open(file) do |fh| AliasList.load(fh, alias_line_parser) end end |
.load_from_lines(lines, alias_line_parser = AliasLineParser::Zsh.new) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/alias_metrics/alias_list.rb', line 16 def load_from_lines(lines, alias_line_parser=AliasLineParser::Zsh.new) alias_hash = Hash::new lines.each do |line| alias_, real = alias_line_parser.parse(line) alias_hash[alias_] = real end AliasList.new(alias_hash) end |
.load_from_stdin(alias_line_parser = AliasLineParser::Zsh.new) ⇒ Object
25 26 27 |
# File 'lib/alias_metrics/alias_list.rb', line 25 def load_from_stdin(alias_line_parser=AliasLineParser::Zsh.new) AliasList.load(STDIN, alias_line_parser) end |
Instance Method Details
#appliable_alias(command) ⇒ Object
47 48 49 50 |
# File 'lib/alias_metrics/alias_list.rb', line 47 def appliable_alias(command) alias_ = command.split(/\s/).first @alias_hash.has_key?(alias_) ? alias_ : nil end |
#expand_command(command) ⇒ Object
NOTE: Since #command >> #alias, this process do fastly
38 39 40 41 42 43 44 45 |
# File 'lib/alias_metrics/alias_list.rb', line 38 def (command) @alias_hash.each_pair do |alias_, real| if used_subcommand?(command, alias_) command = command.sub(alias_, real) end end command end |
#shorten_command(command) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/alias_metrics/alias_list.rb', line 72 def shorten_command(command) = (command) ret = Array.new @alias_hash.each_pair do |alias_, real| if used_subcommand?(, real) ret << .sub(real, alias_) if real.length > alias_.length end end ret end |
#shortenable?(command) ⇒ Boolean
NOTE: Since #command >> #alias, this process do fastly
53 54 55 56 57 58 59 60 |
# File 'lib/alias_metrics/alias_list.rb', line 53 def shortenable?(command) @alias_hash.each_pair do |alias_, real| if used_subcommand?(command, real) return true if real.length > alias_.length end end false end |
#shortenable_alias(command) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/alias_metrics/alias_list.rb', line 62 def shortenable_alias(command) ret = [] @alias_hash.each_pair do |alias_, real| if used_subcommand?(command, real) ret << alias_ if real.length > alias_.length end end ret end |