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)


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

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)


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

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


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

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


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

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.


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

def label o
  o.to_s
end

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

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


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

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


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

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

#the_uc(o) ⇒ Object

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


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

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