Class: MKBrut::Prefix
- Inherits:
-
Object
- Object
- MKBrut::Prefix
- Defined in:
- lib/mkbrut/prefix.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(identifier) ⇒ Prefix
constructor
A new instance of Prefix.
- #to_s ⇒ Object (also: #to_str)
Constructor Details
#initialize(identifier) ⇒ Prefix
Returns a new instance of Prefix.
13 14 15 16 17 18 19 20 21 |
# File 'lib/mkbrut/prefix.rb', line 13 def initialize(identifier) @identifier = identifier.to_s if @identifier.length != 2 raise InvalidIdentifier, "prefix '#{@identifier}' must be 2 characters" end if @identifier !~ /^[a-z]+$/ raise InvalidIdentifier, "prefix must be only lower case ASCII letters" end end |
Class Method Details
.from_app_id(app_id) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/mkbrut/prefix.rb', line 3 def self.from_app_id(app_id) app_id = app_id.to_s prefix = if app_id =~ /^[^-]+[a-z]-[a-z]/ app_id.split("-")[0..1].map { it[0] }.join("") else app_id[0..1] end self.new(prefix) end |
Instance Method Details
#to_s ⇒ Object Also known as: to_str
23 |
# File 'lib/mkbrut/prefix.rb', line 23 def to_s = @identifier |