Class: SublimeDSL::SublimeText::CommandSet::Item
- Inherits:
-
Object
- Object
- SublimeDSL::SublimeText::CommandSet::Item
- Defined in:
- lib/sublime_dsl/sublime_text/command_set.rb
Instance Attribute Summary collapse
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(caption, command) ⇒ Item
constructor
A new instance of Item.
- #to_dsl ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(caption, command) ⇒ Item
Returns a new instance of Item.
59 60 61 62 |
# File 'lib/sublime_dsl/sublime_text/command_set.rb', line 59 def initialize(caption, command) @caption = caption @command = command end |
Instance Attribute Details
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
57 58 59 |
# File 'lib/sublime_dsl/sublime_text/command_set.rb', line 57 def caption @caption end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
57 58 59 |
# File 'lib/sublime_dsl/sublime_text/command_set.rb', line 57 def command @command end |
Class Method Details
.from_json(json_hash) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/sublime_dsl/sublime_text/command_set.rb', line 48 def self.from_json(json_hash) h = json_hash.dup cap = h.delete('caption') or raise Error, "no caption: #{json_hash.inspect}" cmd = h.delete('command') or raise Error, "no command: #{json_hash.inspect}" args = h.delete('args') h.empty? or warn "unkown keys ignored: #{h.inspect}" new(cap, Command.new(cmd, args)) end |
Instance Method Details
#to_dsl ⇒ Object
64 65 66 |
# File 'lib/sublime_dsl/sublime_text/command_set.rb', line 64 def to_dsl "item #{caption.to_source}, #{command.to_dsl}" end |
#to_h ⇒ Object
68 69 70 |
# File 'lib/sublime_dsl/sublime_text/command_set.rb', line 68 def to_h { 'caption' => caption }.merge(command.to_h) end |