Class: Fatty::History::Entry
- Inherits:
-
Object
- Object
- Fatty::History::Entry
- Defined in:
- lib/fatty/history/entry.rb
Instance Attribute Summary collapse
-
#ctx ⇒ Object
readonly
Returns the value of attribute ctx.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#stamp ⇒ Object
readonly
Returns the value of attribute stamp.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
- #command? ⇒ Boolean
- #ctx_fetch(key, default = nil) ⇒ Object
-
#initialize(text:, kind: :command, ctx: nil, stamp: nil) ⇒ Entry
constructor
A new instance of Entry.
- #search? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(text:, kind: :command, ctx: nil, stamp: nil) ⇒ Entry
Returns a new instance of Entry.
8 9 10 11 12 13 |
# File 'lib/fatty/history/entry.rb', line 8 def initialize(text:, kind: :command, ctx: nil, stamp: nil) @text = text.to_s @kind = kind.to_sym @ctx = normalize_ctx(ctx) @stamp = stamp || Time.now end |
Instance Attribute Details
#ctx ⇒ Object (readonly)
Returns the value of attribute ctx.
6 7 8 |
# File 'lib/fatty/history/entry.rb', line 6 def ctx @ctx end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
6 7 8 |
# File 'lib/fatty/history/entry.rb', line 6 def kind @kind end |
#stamp ⇒ Object (readonly)
Returns the value of attribute stamp.
6 7 8 |
# File 'lib/fatty/history/entry.rb', line 6 def stamp @stamp end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
6 7 8 |
# File 'lib/fatty/history/entry.rb', line 6 def text @text end |
Class Method Details
.from_h(hash) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fatty/history/entry.rb', line 36 def self.from_h(hash) hash = hash.transform_keys(&:to_s) new( text: hash.fetch("text", ""), kind: hash.fetch("kind", "command").to_sym, ctx: History.normalize_ctx(hash["ctx"]), stamp: parse_stamp(hash["stamp"]), ) end |
Instance Method Details
#command? ⇒ Boolean
24 25 26 |
# File 'lib/fatty/history/entry.rb', line 24 def command? kind == :command end |
#ctx_fetch(key, default = nil) ⇒ Object
32 33 34 |
# File 'lib/fatty/history/entry.rb', line 32 def ctx_fetch(key, default = nil) ctx.fetch(key.to_s, default) end |
#search? ⇒ Boolean
28 29 30 |
# File 'lib/fatty/history/entry.rb', line 28 def search? kind == :search_string || kind == :search_regex end |
#to_h ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/fatty/history/entry.rb', line 15 def to_h { "text" => text, "kind" => kind.to_s, "ctx" => ctx, "stamp" => stamp.iso8601 } end |