Class: Roar::JSON::JSONAPI::MemberName
- Inherits:
-
Object
- Object
- Roar::JSON::JSONAPI::MemberName
- Defined in:
- lib/roar/json/json_api/member_name.rb
Overview
Member Name formatting according to the JSON API specification.
Constant Summary collapse
- LENIENT_FILTER_REGEXP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/([^[:alnum:][-_ ]]+)/
- STRICT_FILTER_REGEXP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/([^[0-9a-z][-_]]+)/
Class Method Summary collapse
Instance Method Summary collapse
-
#call(name, options = {}) ⇒ String
Format a member name.
Class Method Details
.call(name, options = {}) ⇒ Object
17 18 19 |
# File 'lib/roar/json/json_api/member_name.rb', line 17 def self.call(name, = {}) new.(name, ) end |
Instance Method Details
#call(name, options = {}) ⇒ String
Format a member name
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/roar/json/json_api/member_name.rb', line 40 def call(name, = {}) name = name.to_s strict = .fetch(:strict, true) if strict name.downcase! name.gsub!(STRICT_FILTER_REGEXP, ''.freeze) else name.gsub!(LENIENT_FILTER_REGEXP, ''.freeze) end name.gsub!(/\A([-_ ])/, '') name.gsub!(/([-_ ])\z/, '') name.tr!('_', '-') if strict name end |