Class: SublimeDSL::SublimeText::CommandSet
- Inherits:
-
Object
- Object
- SublimeDSL::SublimeText::CommandSet
- Defined in:
- lib/sublime_dsl/sublime_text/command_set.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #export(dir) ⇒ Object
-
#initialize(name) ⇒ CommandSet
constructor
A new instance of CommandSet.
- #to_dsl ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(name) ⇒ CommandSet
Returns a new instance of CommandSet.
23 24 25 26 |
# File 'lib/sublime_dsl/sublime_text/command_set.rb', line 23 def initialize(name) @name = name @items = [] end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
21 22 23 |
# File 'lib/sublime_dsl/sublime_text/command_set.rb', line 21 def items @items end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/sublime_dsl/sublime_text/command_set.rb', line 21 def name @name end |
Class Method Details
.import(file) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sublime_dsl/sublime_text/command_set.rb', line 8 def self.import(file) name = File.basename(file, File.extname(file)) set = new(name) list = JSON[File.read(file, encoding: 'utf-8')] begin set.items.concat list.map { |h| Item.from_json(h) } rescue => ex Console.error "file: #{file}" raise ex end set end |
Instance Method Details
#export(dir) ⇒ Object
34 35 36 37 |
# File 'lib/sublime_dsl/sublime_text/command_set.rb', line 34 def export(dir) file = "#{dir}/#{name}.sublime-commands" File.open(file, 'wb:utf-8') { |f| f.write to_json } end |
#to_dsl ⇒ Object
28 29 30 31 32 |
# File 'lib/sublime_dsl/sublime_text/command_set.rb', line 28 def to_dsl dsl = "commands #{name.to_source} do\n\n" items.each { |i| dsl << " #{i.to_dsl}\n" } dsl << "\nend" end |
#to_json ⇒ Object
39 40 41 42 43 |
# File 'lib/sublime_dsl/sublime_text/command_set.rb', line 39 def to_json "[\n" << items.map { |i| JSON.generate(i.to_h) }.join(",\n").indent(2) << "\n]" end |