Class: VER::Snippet

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

Overview

TODO: transformations

Constant Summary collapse

LITERAL_BACKTICK =
/\\`/
LITERAL_DOLLAR =
/\\\$/
LITERAL_BACKSLASH =
/\\/
PLAIN_TEXT =
/[^\\`$]+/
TAB_STOP =
/\$(\d+)/
NESTED_TAB_STOP =
/^\$\{(?<id>\d+):(?<nested>((?<pg>\$\{(?:\\\$\{|\\\}|[^\\}$]|\g<pg>)*\})|(?:\\\}|\\\$\{|[^$}]))+)\}/
SUBSTITUTE_VARIABLE =
/\$(#{variable})/
SUBSTITUTE_VARIABLE_WITH_DEFAULT =
/\$\{(#{variable}):([^}]+)\}/
SUBSTITUTE_VARIABLE_WITH_REGEXP =
/\$\{(#{variable})\/(#{regexp})\/(#{format})\/(#{options})\}/
SUBSTITUTE_SHELL_CODE =
/`((?:\\`|[^`\\]+)*)`/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snippet, env = {}) ⇒ Snippet

Returns a new instance of Snippet.



160
161
162
163
# File 'lib/ver/methods/snippet.rb', line 160

def initialize(snippet, env = {})
  @snippet = snippet
  @env = env
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



158
159
160
# File 'lib/ver/methods/snippet.rb', line 158

def env
  @env
end

Instance Method Details

#apply_on(buffer) ⇒ Object



175
176
177
178
# File 'lib/ver/methods/snippet.rb', line 175

def apply_on(buffer)
  parse(@snippet, out = [])
  apply_out_on(buffer, out)
end

#resultObject



170
171
172
173
# File 'lib/ver/methods/snippet.rb', line 170

def result
  parse(@snippet, out = [])
  out
end

#to_sObject



165
166
167
168
# File 'lib/ver/methods/snippet.rb', line 165

def to_s
  parse(@snippet, out = [])
  out.join
end