class Phrase
Public Class Methods
new(dsl_string)
click to toggle source
# File lib/dunmanifestin/phrase.rb, line 16 def initialize dsl_string raise "Try again." unless dsl_string @dsl_string = dsl_string end
Public Instance Methods
reify(genre, requested_inflections = [])
click to toggle source
# File lib/dunmanifestin/phrase.rb, line 21 def reify genre, requested_inflections = [] vals = variables.map { |variable| variable.reify genre, requested_inflections } inflect requested_inflections, constant_segments.zip(vals).flatten.join('') end
Private Instance Methods
constant_segments()
click to toggle source
# File lib/dunmanifestin/phrase.rb, line 34 def constant_segments parsed_dsl[:constant_segments] end
inflect(inflections, string)
click to toggle source
# File lib/dunmanifestin/phrase.rb, line 51 def inflect inflections, string plural = inflections.include? :plural article = inflections.include? :article possessive = inflections.include? :possessive capitalize = inflections.include? :capitalize titleize = inflections.include? :titleize # Good, now turn this into a stateless function. string = string.pluralize if plural && variables.none?(&:delegated_plural?) string = (string =~ /s$/) ? "#{string}'" : "#{string}'s" if plural && possessive && variables.none?(&:delegated_plural?) string = "#{string}'s" if !plural && possessive && variables.none?(&:delegated_possessive?) string = (string =~ /^[aeiou]/i) ? "an #{string}" : "a #{string}" if !plural && article && variables.none?(&:delegated_article?) string = string[0].capitalize + string[1 .. -1] if capitalize string = string.titleize if titleize string end
parsed_dsl()
click to toggle source
# File lib/dunmanifestin/phrase.rb, line 38 def parsed_dsl @parsed_dsl ||= begin tokens = @dsl_string.split(/[\[\]]/) constant_segments = tokens.even_elements variables = tokens.odd_elements { :variables => variables.map(&Variable.method(:new)), :constant_segments => constant_segments } end end
variables()
click to toggle source
# File lib/dunmanifestin/phrase.rb, line 30 def variables parsed_dsl[:variables] end