module Puppet::Pops::LabelProvider

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

Constants

A
AN
SKIPPED_CHARACTERS
VOWELS

Public Instance Methods

a_an(o) click to toggle source

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

   # File lib/puppet/pops/label_provider.rb
17 def a_an o
18   text = label(o)
19   "#{article(text)} #{text}"
20 end
a_an_uc(o) click to toggle source

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

   # File lib/puppet/pops/label_provider.rb
23 def a_an_uc o
24   text = label(o)
25   "#{article(text).capitalize} #{text}"
26 end
article(s) click to toggle source

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

   # File lib/puppet/pops/label_provider.rb
63 def article s
64   article_for_letter(first_letter_of(s))
65 end
combine_strings(strings, conjunction = 'or') click to toggle source

Combines several strings using commas and a final conjunction

   # File lib/puppet/pops/label_provider.rb
44 def combine_strings(strings, conjunction = 'or')
45   case strings.size
46   when 0
47     ''
48   when 1
49     strings[0]
50   when 2
51     "#{strings[0]} #{conjunction} #{strings[1]}"
52   else
53     "#{strings[0...-1].join(', ')}, #{conjunction} #{strings.last}"
54   end
55 end
label(o) click to toggle source

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.

   # File lib/puppet/pops/label_provider.rb
12 def label o
13   o.to_s
14 end
plural_s(count, text = '') click to toggle source

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

   # File lib/puppet/pops/label_provider.rb
39 def plural_s(count, text = '')
40   count == 1 ? text : "#{text}s"
41 end
the(o) click to toggle source

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

   # File lib/puppet/pops/label_provider.rb
29 def the o
30   "the #{label(o)}"
31 end
the_uc(o) click to toggle source

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

   # File lib/puppet/pops/label_provider.rb
34 def the_uc o
35   "The #{label(o)}"
36 end

Private Instance Methods

article_for_letter(letter) click to toggle source
   # File lib/puppet/pops/label_provider.rb
82 def article_for_letter(letter)
83   downcased = letter.downcase
84   if VOWELS.include? downcased
85     AN
86   else
87     A
88   end
89 end
first_letter_of(string) click to toggle source
   # File lib/puppet/pops/label_provider.rb
69 def first_letter_of(string)
70   char = string[0,1]
71   if SKIPPED_CHARACTERS.include? char
72     char = string[1,1]
73   end
74 
75   if char == ""
76     raise Puppet::DevError, _("<%{string}> does not appear to contain a word") % { string: string }
77   end
78 
79   char
80 end