Class: SpecI18n::Parser::NaturalLanguage
- Inherits:
-
Object
- Object
- SpecI18n::Parser::NaturalLanguage
- 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
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
Class Method Summary collapse
Instance Method Summary collapse
- #before_and_after_keywords ⇒ Object
- #dsl_keywords ⇒ Object
- #example_group_keywords ⇒ Object
- #expectation_keywords ⇒ Object
- #hooks_params_keywords ⇒ Object
- #incomplete? ⇒ Boolean
-
#initialize(language) ⇒ NaturalLanguage
constructor
A new instance of NaturalLanguage.
- #its_keywords ⇒ Object
- #spec_keywords(key, space = false) ⇒ Object
- #subject_keywords ⇒ Object
- #word_be(ruby_type) ⇒ Object
Constructor Details
#initialize(language) ⇒ NaturalLanguage
Returns a new instance of NaturalLanguage.
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
#keywords ⇒ Object (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
Instance Method Details
#before_and_after_keywords ⇒ Object
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_keywords ⇒ Object
28 29 30 |
# File 'lib/spec-i18n/parser/natural_language.rb', line 28 def dsl_keywords spec_keywords("describe") end |
#example_group_keywords ⇒ Object
51 52 53 |
# File 'lib/spec-i18n/parser/natural_language.rb', line 51 def example_group_keywords spec_keywords("it") end |
#expectation_keywords ⇒ Object
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_keywords ⇒ Object
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
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_keywords ⇒ Object
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_keywords ⇒ Object
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 |