Class: Gherkin::I18n

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

.allObject

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

.languagesObject



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_keywordsObject



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_keywordsObject



53
54
55
# File 'lib/gherkin/i18n.rb', line 53

def examples_keywords
  keywords('examples')
end

#feature_keywordsObject



37
38
39
# File 'lib/gherkin/i18n.rb', line 37

def feature_keywords
  keywords('feature')
end

#incomplete?Boolean

Returns:

  • (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_keyObject



29
30
31
# File 'lib/gherkin/i18n.rb', line 29

def sanitized_key
  @key.gsub(/[\s-]/, '')
end

#scenario_keywordsObject



41
42
43
# File 'lib/gherkin/i18n.rb', line 41

def scenario_keywords
  keywords('scenario')
end

#scenario_outline_keywordsObject



45
46
47
# File 'lib/gherkin/i18n.rb', line 45

def scenario_outline_keywords
  keywords('scenario_outline')
end

#step_keywordsObject



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