Module: Puppet::Pops::LabelProvider

Included in:
Puppet::Pops::Lookup::HieraConfig, Model::ModelLabelProvider, Time::TimeData, Types::TypeMismatch
Defined in:
lib/puppet/pops/label_provider.rb

Overview

Provides a label for an object. This simple implementation calls #to_s on the given object, and handles articles ‘a/an/the’.

Constant Summary collapse

VOWELS =
%w[a e i o u y]
SKIPPED_CHARACTERS =
%w[" ']
A =
"a"
AN =
"an"

Instance Method Summary collapse

Instance Method Details

#a_an(o) ⇒ Object

Produces a label for the given text with indefinite article (a/an)



19
20
21
22
# File 'lib/puppet/pops/label_provider.rb', line 19

def a_an o
  text = label(o)
  "#{article(text)} #{text}"
end

#a_an_uc(o) ⇒ Object

Produces a label for the given text with indefinite article (A/An)



25
26
27
28
# File 'lib/puppet/pops/label_provider.rb', line 25

def a_an_uc o
  text = label(o)
  "#{article(text).capitalize} #{text}"
end

#article(s) ⇒ Object

Produces an *indefinite article* (a/an) for the given text (‘a’ if it starts with a vowel) This is obviously flawed in the general sense as may labels have punctuation at the start and this method does not translate punctuation to English words. Also, if a vowel is pronounced as a consonant, the article should not be “an”.



65
66
67
# File 'lib/puppet/pops/label_provider.rb', line 65

def article s
  article_for_letter(first_letter_of(s))
end

#combine_strings(strings, conjunction = 'or') ⇒ Object

Combines several strings using commas and a final conjunction



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puppet/pops/label_provider.rb', line 46

def combine_strings(strings, conjunction = 'or')
  case strings.size
  when 0
    ''
  when 1
    strings[0]
  when 2
    "#{strings[0]} #{conjunction} #{strings[1]}"
  else
    "#{strings[0...-1].join(', ')}, #{conjunction} #{strings.last}"
  end
end

#label(o) ⇒ Object

Provides a label for the given object by calling ‘to_s` on the object. The intent is for this method to be overridden in concrete label providers.



14
15
16
# File 'lib/puppet/pops/label_provider.rb', line 14

def label o
  o.to_s
end

#plural_s(count, text = '') ⇒ Object

Appends ‘s’ to (optional) text if count != 1 else an empty string



41
42
43
# File 'lib/puppet/pops/label_provider.rb', line 41

def plural_s(count, text = '')
  count == 1 ? text : "#{text}s"
end

#the(o) ⇒ Object

Produces a label for the given text with *definite article* (the).



31
32
33
# File 'lib/puppet/pops/label_provider.rb', line 31

def the o
  "the #{label(o)}"
end

#the_uc(o) ⇒ Object

Produces a label for the given text with *definite article* (The).



36
37
38
# File 'lib/puppet/pops/label_provider.rb', line 36

def the_uc o
  "The #{label(o)}"
end