This file is indexed.

/usr/lib/ruby/vendor_ruby/inflecto.rb is in ruby-inflecto 0.0.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# The Inflecto transforms words from singular to plural, class names to table names, modularized class names to ones without,
# and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept
# in inflections.rb.
#
# The Rails core team has stated patches for the inflections library will not be accepted
# in order to avoid breaking legacy applications which may be relying on errant inflections.
# If you discover an incorrect inflection and require it for your application, you'll need
# to correct it yourself (explained below).
module Inflecto

  # Convert input to UpperCamelCase
  #
  # Will also convert '/' to '::' which is useful for converting paths to namespaces.
  #
  # @param [String] input
  #
  # @example
  #   Inflecto.camelize("data_mapper")        # => "DataMapper"
  #   Inflecto.camelize("data_mapper/errors") # => "DataMApper::Errors"
  #
  # @return [String]
  # 
  # @api public
  #
  def self.camelize(input)
    input.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  end

  # Convert input to underscored, lowercase string 
  #
  # Changes '::' to '/' to convert namespaces to paths.
  #
  # @param [String] input
  #
  # @example
  #   Inflecto.underscore("DataMapper")         # => "data_mapper"
  #   Inflecto.underscore("DataMapper::Errors") # => "data_mapper/errors"
  #
  # @return [String]
  #
  # @api public
  #
  def self.underscore(input)
    word = input.to_s.dup
    word.gsub!(/::/, '/')
    word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
    word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
    word.tr!("-", "_")
    word.downcase!
    word
  end

  # Convert input underscores to dashes 
  #
  # @param [String] input
  #
  # @example
  #   Inflecto.dasherize("foo_bar") # => "foo-bar"
  #
  # @return [String]
  #
  # @api public
  #
  def self.dasherize(input)
    input.gsub(/_/, '-')
  end

  # Return unscoped constant name
  #
  # @param [String] input
  #
  # @example
  #
  #   Inflecto.demodulize("DataMapper::Error") # => "Error"
  #   Inflecto.demodulize("DataMapper")        # => "DataMapper"
  #
  # @return [String]
  #
  # @api public
  #
  def self.demodulize(input)
    input.to_s.gsub(/^.*::/, '')
  end

  # Creates a foreign key name 
  #
  # @param [String] input
  #
  # @example
  #
  #   Inflecto.foreign_key("Message) => "message_id"
  #
  # @return [String]
  #
  # @api private
  #
  def self.foreign_key(input)
    "#{underscore(demodulize(input))}_id"
  end

  # Find a constant with the name specified in the argument string
  #
  # The name is assumed to be the one of a top-level constant, constant scope of caller is igored
  #
  # @param [String] input
  #
  # @example
  #
  #   Inflecto.constantize("Module")            # => Module
  #   Inflecto.constantize("DataMapper::Error") # => Test::Unit
  #
  # @return [Class, Module]
  #
  # @api private
  #
  def self.constantize(input)
    names = input.split('::')
    names.shift if names.empty? || names.first.empty?

    constant = Object
    names.each do |name|
      # Ruby 1.9 introduces an inherit argument for Module#const_get and
      # #const_defined? and changes their default behavior.
      if Module.method(:const_get).arity == 1
        constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
      else
        constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
      end
    end
    constant
  end

  # Convert a number into an ordinal string 
  #
  # @param [Fixnum] number
  #
  # @example
  #
  #   ordinalize(1)     # => "1st"
  #   ordinalize(2)     # => "2nd"
  #   ordinalize(1002)  # => "1002nd"
  #   ordinalize(1003)  # => "1003rd"
  #
  # @return [String]
  #
  # @api private
  #
  def self.ordinalize(number)
    if (11..13).include?(number.to_i % 100)
      "#{number}th"
    else
      case number.to_i % 10
        when 1; "#{number}st"
        when 2; "#{number}nd"
        when 3; "#{number}rd"
        else    "#{number}th"
      end
    end
  end

  # Yields a singleton instance of Inflecto::Inflections 
  #
  # @example
  #
  #   Inflecto.inflections do |inflect|
  #     inflect.uncountable "rails"
  #   end
  #
  # @return [Inflecto::Inflections]
  #
  # @api public
  #
  def self.inflections
    if block_given?
      yield Inflections.instance
    else
      Inflections.instance
    end
  end

  # Convert input word string to plural 
  #
  # @param [String] word
  #
  # @example
  #
  #   Inflecto.pluralize("post")         # => "posts"
  #   Inflecto.pluralize("octopus")      # => "octopi"
  #   Inflecto.pluralize("sheep")        # => "sheep"
  #   Inflecto.pluralize("words")        # => "words"
  #   Inflecto.pluralize("CamelOctopus") # => "CamelOctopi"
  #
  # @return [String]
  #
  # @api public
  #
  def self.pluralize(word)
    result = word.to_s.dup

    if result.empty? || inflections.uncountables.include?(result.downcase)
      result
    else
      inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
      result
    end
  end

  # Convert word to singular
  #
  # @param [String] word
  #
  # @example
  #
  #   Inflecto.singularize("posts") # => "post"
  #   Inflecto.singularize("octopi") # => "octopus"
  #   Inflecto.singularize("sheep") # => "sheep"
  #   Inflecto.singularize("word") # => "word"
  #   Inflecto.singularize("CamelOctopi") # => "CamelOctopus"
  #
  # @return [String]
  #
  # @api public
  #
  def self.singularize(word)
    result = word.to_s.dup

    if inflections.uncountables.any? { |inflection| result =~ /\b(#{inflection})\Z/i }
      result
    else
      inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
      result
    end
  end

  # Humanize string
  #
  # @param [String] input
  #
  # capitalizes the first word and turns underscores into spaces and strips a # trailing "_id", if any. 
  # Like +titleize+, this is meant for creating pretty output.
  #
  # @example
  #
  #   Inflecto.humanize("employee_salary") # => "Employee salary"
  #   Inflecto.humanize("author_id")       # => "Author"
  #
  # @return [String]
  #
  # @api private
  #
  def self.humanize(input)
    result = input.to_s.dup

    inflections.humans.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
    result.gsub(/_id$/, "").gsub(/_/, " ").capitalize
  end


  # Tabelize input string 
  #
  # @param [String] input
  #
  # Create the name of a table like Rails does for models to table names. 
  # This method # uses the +pluralize+ method on the last word in the string.
  #
  # @example
  #
  #   Inflecto.tabelize("RawScaledScorer") # => "raw_scaled_scorers"
  #   Inflecto.tabelize("egg_and_ham")     # => "egg_and_hams"
  #   Inflecto.tabelize("fancyCategory")   # => "fancy_categories"
  #
  # @return [String]
  #
  # @api private
  #
  def self.tableize(input)
    pluralize(underscore(input).gsub('/','_'))
  end

  # Classify input 
  #
  # Create a class name from a plural table name like Rails does for table names to models.
  # Note that this returns a string and not a Class. 
  #
  # To convert to an actual class # follow +classify+ with +constantize+.
  #
  # @examples:
  #
  #   Inflecto.classify("egg_and_hams") # => "EggAndHam"
  #   Inflecto.classify("posts")        # => "Post"
  #
  #   # Singular names are not handled correctly:
  #   Inflecto.classify("business")     # => "Busines"
  #
  # @return [String]
  #
  # @api private
  #
  def self.classify(table_name)
    # strip out any leading schema name
    camelize(singularize(table_name.to_s.sub(/.*\./, '')))
  end

end

require 'inflecto/inflections'
require 'inflecto/defaults'