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)



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

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)



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

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”.



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

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



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

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.



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

def label o
  o.to_s
end

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

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



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

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).



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

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

#the_uc(o) ⇒ Object

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



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

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