Class: Gamefic::Syntax::Template
- Inherits:
-
Object
- Object
- Gamefic::Syntax::Template
- Defined in:
- lib/gamefic/syntax/template.rb
Overview
Template data for syntaxes.
Constant Summary collapse
- PARAM_REGEXP =
/^:[a-z0-9_]+$/i.freeze
Instance Attribute Summary collapse
- #params ⇒ Array<String> readonly
- #text ⇒ String readonly
Class Method Summary collapse
Instance Method Summary collapse
- #compare(other) ⇒ Object
-
#initialize(text) ⇒ Template
constructor
A new instance of Template.
- #keywords ⇒ Object
- #regexp ⇒ Object
- #to_s ⇒ Object
- #verb ⇒ Object
Constructor Details
#initialize(text) ⇒ Template
Returns a new instance of Template.
16 17 18 19 |
# File 'lib/gamefic/syntax/template.rb', line 16 def initialize text @text = text.normalize @params = @text.keywords.select { |word| word.start_with?(':') } end |
Instance Attribute Details
#params ⇒ Array<String> (readonly)
14 15 16 |
# File 'lib/gamefic/syntax/template.rb', line 14 def params @params end |
#text ⇒ String (readonly)
11 12 13 |
# File 'lib/gamefic/syntax/template.rb', line 11 def text @text end |
Class Method Details
Instance Method Details
#compare(other) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/gamefic/syntax/template.rb', line 37 def compare other if keywords.length == other.keywords.length other.verb <=> verb else other.keywords.length <=> keywords.length end end |
#keywords ⇒ Object
21 22 23 |
# File 'lib/gamefic/syntax/template.rb', line 21 def keywords text.keywords end |
#regexp ⇒ Object
29 30 31 |
# File 'lib/gamefic/syntax/template.rb', line 29 def regexp @regexp ||= Regexp.new("^#{make_tokens.join(' ')}$", Regexp::IGNORECASE) end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/gamefic/syntax/template.rb', line 25 def to_s text end |
#verb ⇒ Object
33 34 35 |
# File 'lib/gamefic/syntax/template.rb', line 33 def verb @verb ||= Syntax.literal_or_nil(keywords.first) end |