Class: Appydave::Tools::ZshHistory::Parser
- Inherits:
-
Object
- Object
- Appydave::Tools::ZshHistory::Parser
- Defined in:
- lib/appydave/tools/zsh_history/parser.rb
Overview
Parses ZSH history file, handling multi-line commands with \ continuations
Constant Summary collapse
- HISTORY_LINE_PATTERN =
ZSH history line format: : timestamp:duration;command
/^: (\d+):\d+;(.*)$/.freeze
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Instance Method Summary collapse
-
#initialize(file_path = nil) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(file_path = nil) ⇒ Parser
Returns a new instance of Parser.
13 14 15 16 |
# File 'lib/appydave/tools/zsh_history/parser.rb', line 13 def initialize(file_path = nil) @file_path = file_path || default_history_path @commands = [] end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
11 12 13 |
# File 'lib/appydave/tools/zsh_history/parser.rb', line 11 def commands @commands end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
11 12 13 |
# File 'lib/appydave/tools/zsh_history/parser.rb', line 11 def file_path @file_path end |
Instance Method Details
#parse ⇒ Object
18 19 20 21 22 23 |
# File 'lib/appydave/tools/zsh_history/parser.rb', line 18 def parse return [] unless File.exist?(file_path) lines = read_file @commands = parse_lines(lines) end |