Class: Gherkin::I18n
- Inherits:
-
Object
- Object
- Gherkin::I18n
- Defined in:
- lib/gherkin/i18n.rb
Constant Summary collapse
- KEYWORD_KEYS =
%w{name native feature background scenario scenario_outline examples given when then and but}
- LANGUAGES =
YAML.load_file(File.dirname(__FILE__) + '/i18n.yml')
Class Method Summary collapse
-
.all ⇒ Object
Used by code generators for other lexer tools like pygments lexer and textmate bundle.
- .get(key) ⇒ Object
- .languages ⇒ Object
Instance Method Summary collapse
- #and_keywords(space = true) ⇒ Object
- #background_keywords ⇒ Object
- #but_keywords(space = true) ⇒ Object
- #examples_keywords ⇒ Object
- #feature_keywords ⇒ Object
- #incomplete? ⇒ Boolean
-
#initialize(key) ⇒ I18n
constructor
A new instance of I18n.
- #keywords(key, space = false) ⇒ Object
- #sanitized_key ⇒ Object
- #scenario_keywords ⇒ Object
- #scenario_outline_keywords ⇒ Object
- #step_keywords ⇒ Object
Constructor Details
#initialize(key) ⇒ I18n
Returns a new instance of I18n.
21 22 23 24 25 26 27 |
# File 'lib/gherkin/i18n.rb', line 21 def initialize(key) @key = key @keywords = LANGUAGES[key] raise "Language not supported: #{key.inspect}" if @key.nil? @keywords['grammar_name'] = @keywords['name'].gsub(/\s/, '') @parser = nil end |
Class Method Details
.all ⇒ Object
Used by code generators for other lexer tools like pygments lexer and textmate bundle
8 9 10 |
# File 'lib/gherkin/i18n.rb', line 8 def all LANGUAGES.keys.sort.map{|key| get(key)} end |
.get(key) ⇒ Object
12 13 14 |
# File 'lib/gherkin/i18n.rb', line 12 def get(key) languages[key] ||= new(key) end |
.languages ⇒ Object
16 17 18 |
# File 'lib/gherkin/i18n.rb', line 16 def languages @languages ||= {} end |
Instance Method Details
#and_keywords(space = true) ⇒ Object
61 62 63 |
# File 'lib/gherkin/i18n.rb', line 61 def and_keywords(space=true) keywords('and', space) end |
#background_keywords ⇒ Object
49 50 51 |
# File 'lib/gherkin/i18n.rb', line 49 def background_keywords keywords('background') end |
#but_keywords(space = true) ⇒ Object
57 58 59 |
# File 'lib/gherkin/i18n.rb', line 57 def but_keywords(space=true) keywords('but', space) end |
#examples_keywords ⇒ Object
53 54 55 |
# File 'lib/gherkin/i18n.rb', line 53 def examples_keywords keywords('examples') end |
#feature_keywords ⇒ Object
37 38 39 |
# File 'lib/gherkin/i18n.rb', line 37 def feature_keywords keywords('feature') end |
#incomplete? ⇒ Boolean
33 34 35 |
# File 'lib/gherkin/i18n.rb', line 33 def incomplete? KEYWORD_KEYS.detect{|key| @keywords[key].nil?} end |
#keywords(key, space = false) ⇒ Object
69 70 71 72 |
# File 'lib/gherkin/i18n.rb', line 69 def keywords(key, space=false) raise "No #{key} in #{@keywords.inspect}" if @keywords[key].nil? @keywords[key].split('|').map{|kw| space ? keyword_space(kw) : kw} end |
#sanitized_key ⇒ Object
29 30 31 |
# File 'lib/gherkin/i18n.rb', line 29 def sanitized_key @key.gsub(/[\s-]/, '') end |
#scenario_keywords ⇒ Object
41 42 43 |
# File 'lib/gherkin/i18n.rb', line 41 def scenario_keywords keywords('scenario') end |
#scenario_outline_keywords ⇒ Object
45 46 47 |
# File 'lib/gherkin/i18n.rb', line 45 def scenario_outline_keywords keywords('scenario_outline') end |
#step_keywords ⇒ Object
65 66 67 |
# File 'lib/gherkin/i18n.rb', line 65 def step_keywords %w{given when then and but}.map{|key| keywords(key, true)}.flatten.uniq end |