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
18 def a_an o
19   text = label(o)
20   "#{article(text)} #{text}"
21 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
24 def a_an_uc o
25   text = label(o)
26   "#{article(text).capitalize} #{text}"
27 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
64 def article s
65   article_for_letter(first_letter_of(s))
66 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
45 def combine_strings(strings, conjunction = 'or')
46   case strings.size
47   when 0
48     ''
49   when 1
50     strings[0]
51   when 2
52     "#{strings[0]} #{conjunction} #{strings[1]}"
53   else
54     "#{strings[0...-1].join(', ')}, #{conjunction} #{strings.last}"
55   end
56 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
13 def label o
14   o.to_s
15 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
40 def plural_s(count, text = '')
41   count == 1 ? text : "#{text}s"
42 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
30 def the o
31   "the #{label(o)}"
32 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
35 def the_uc o
36   "The #{label(o)}"
37 end

Private Instance Methods

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