Class: Snipcheat::Snippet

Inherits:
Object
  • Object
show all
Defined in:
lib/snipcheat/snippet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Snippet

Returns a new instance of Snippet.



7
8
9
10
# File 'lib/snipcheat/snippet.rb', line 7

def initialize(path)
  @path = path
  load
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



6
7
8
# File 'lib/snipcheat/snippet.rb', line 6

def content
  @content
end

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/snipcheat/snippet.rb', line 6

def description
  @description
end

#scopeObject (readonly)

Returns the value of attribute scope.



6
7
8
# File 'lib/snipcheat/snippet.rb', line 6

def scope
  @scope
end

#tab_triggerObject (readonly)

Returns the value of attribute tab_trigger.



6
7
8
# File 'lib/snipcheat/snippet.rb', line 6

def tab_trigger
  @tab_trigger
end

Instance Method Details

#loadObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/snipcheat/snippet.rb', line 12

def load
  mash.each do |key, value|
    underscorized = key.to_s
      .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
      .gsub(/([a-z\d])([A-Z])/,'\1_\2')
      .tr("-", "_")
      .downcase
    instance_variable_set("@#{underscorized}", value.to_s)
  end
end