Class: SpecI18n::Parser::NaturalLanguage

Inherits:
Object
  • Object
show all
Defined in:
lib/spec-i18n/parser/natural_language.rb

Constant Summary collapse

BASIC_KEYWORDS =
%w{ name native describe before after it 
subject its should should_not}
ADVANCED_KEYWORDS =
%w{ hooks matchers}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language) ⇒ NaturalLanguage

Returns a new instance of NaturalLanguage.

Raises:



17
18
19
20
# File 'lib/spec-i18n/parser/natural_language.rb', line 17

def initialize(language)
  @keywords = SpecI18n::SPEC_LANGUAGES[language]
  raise(LanguageNotFound, "Language #{language.to_s} Not Supported") if @keywords.nil?
end

Instance Attribute Details

#keywordsObject (readonly)

Returns the value of attribute keywords.



15
16
17
# File 'lib/spec-i18n/parser/natural_language.rb', line 15

def keywords
  @keywords
end

Class Method Details

.get(language) ⇒ Object



10
11
12
# File 'lib/spec-i18n/parser/natural_language.rb', line 10

def get(language)
  new(language)
end

Instance Method Details

#before_and_after_keywordsObject



37
38
39
40
# File 'lib/spec-i18n/parser/natural_language.rb', line 37

def before_and_after_keywords
  adverbs = spec_keywords("before")
  adverbs.merge(spec_keywords("after"))
end

#dsl_keywordsObject



28
29
30
# File 'lib/spec-i18n/parser/natural_language.rb', line 28

def dsl_keywords
  spec_keywords("describe")
end

#example_group_keywordsObject



51
52
53
# File 'lib/spec-i18n/parser/natural_language.rb', line 51

def example_group_keywords
  spec_keywords("it")
end

#expectation_keywordsObject



32
33
34
35
# File 'lib/spec-i18n/parser/natural_language.rb', line 32

def expectation_keywords
  language_adverbs = spec_keywords("should")
  language_adverbs.merge(spec_keywords("should_not"))
end

#hooks_params_keywordsObject



42
43
44
45
46
47
48
49
# File 'lib/spec-i18n/parser/natural_language.rb', line 42

def hooks_params_keywords
  hooks = {}
  keywords['hooks'].each do |hook, value|
    values = value.split('|')
    hooks[hook] = values
  end
  hooks
end

#incomplete?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/spec-i18n/parser/natural_language.rb', line 22

def incomplete?
  language_words = BASIC_KEYWORDS.collect { |key| keywords[key].nil? }
  return true if language_words.include?(true)
  false
end

#its_keywordsObject



59
60
61
# File 'lib/spec-i18n/parser/natural_language.rb', line 59

def its_keywords
  spec_keywords("its")
end

#spec_keywords(key, space = false) ⇒ Object



71
72
73
74
75
# File 'lib/spec-i18n/parser/natural_language.rb', line 71

def spec_keywords(key, space=false)
  raise "No #{key} in #{keywords.inspect}" if keywords[key].nil?
  values = keywords[key].split('|')
  { key => values }
end

#subject_keywordsObject



55
56
57
# File 'lib/spec-i18n/parser/natural_language.rb', line 55

def subject_keywords
  adverbs = spec_keywords('subject')
end

#word_be(ruby_type) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/spec-i18n/parser/natural_language.rb', line 63

def word_be(ruby_type)
  matchers_be = keywords['matchers']['be'].to_s.split("|")
  matcher_ruby_type = keywords['matchers']["#{ruby_type}_word"].to_s.split("|")
  matchers_be.collect do |matcher_be|
    matcher_ruby_type.collect { |matcher| "#{matcher_be}_#{matcher}" }
  end.flatten
end