Module: Mongoid::Extensions::String::Inflections
- Included in:
- String
- Defined in:
- lib/mongoid/extensions/string/inflections.rb
Overview
:nodoc:
Constant Summary collapse
- CHAR_CONV =
Represents how special characters will get converted when creating a composite key that should be unique and part of a url.
{ " " => "-", "!" => "-excl-", "\"" => "-bckslsh-", "#" => "-hash-", "$" => "-dol-", "%" => "-perc-", "&" => "-and-", "'" => "-quo-", "(" => "-oparen-", ")" => "-cparen-", "*" => "-astx-", "+" => "-plus-", "," => "-comma-", "-" => "-dash-", "." => "-period-", "/" => "-fwdslsh-", ":" => "-colon-", ";" => "-semicol-", "<" => "-lt-", "=" => "-eq-", ">" => "-gt-", "?" => "-ques-", "@" => "-at-", "[" => "-obrck-", "\\" => "-bckslsh-", "]" => "-clbrck-", "^" => "-carat-", "_" => "-undscr-", "`" => "-bcktick-", "{" => "-ocurly-", "|" => "-pipe-", "}" => "-clcurly-", "~" => "-tilda-" }
- REVERSALS =
{ "asc" => "desc", "ascending" => "descending", "desc" => "asc", "descending" => "ascending" }
Instance Method Summary collapse
- #collectionize ⇒ Object
- #identify ⇒ Object
- #invert ⇒ Object
- #labelize ⇒ Object
- #plural? ⇒ Boolean
- #reader ⇒ Object
- #singular? ⇒ Boolean
- #writer? ⇒ Boolean
Instance Method Details
#collectionize ⇒ Object
58 59 60 |
# File 'lib/mongoid/extensions/string/inflections.rb', line 58 def collectionize tableize.gsub("/", "_") end |
#identify ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/mongoid/extensions/string/inflections.rb', line 62 def identify if Mongoid.parameterize_keys key = "" each_char { |c| key += (CHAR_CONV[c] || c.downcase) }; key else self end end |
#invert ⇒ Object
75 76 77 |
# File 'lib/mongoid/extensions/string/inflections.rb', line 75 def invert REVERSALS[self] end |
#labelize ⇒ Object
71 72 73 |
# File 'lib/mongoid/extensions/string/inflections.rb', line 71 def labelize underscore.humanize end |
#plural? ⇒ Boolean
83 84 85 |
# File 'lib/mongoid/extensions/string/inflections.rb', line 83 def plural? pluralize == self end |
#reader ⇒ Object
87 88 89 |
# File 'lib/mongoid/extensions/string/inflections.rb', line 87 def reader writer? ? gsub("=", "") : self end |
#singular? ⇒ Boolean
79 80 81 |
# File 'lib/mongoid/extensions/string/inflections.rb', line 79 def singular? singularize == self end |
#writer? ⇒ Boolean
91 92 93 |
# File 'lib/mongoid/extensions/string/inflections.rb', line 91 def writer? include?("=") end |