Class: Appydave::Tools::Jump::Location
- Inherits:
-
Object
- Object
- Appydave::Tools::Jump::Location
- Defined in:
- lib/appydave/tools/jump/location.rb
Overview
Location represents a single development folder location
Constant Summary collapse
- VALID_KEY_PATTERN =
/\A[a-z0-9][a-z0-9-]*[a-z0-9]\z|\A[a-z0-9]\z/.freeze
- VALID_PATH_PATTERN =
%r{\A[~/]}.freeze
- VALID_TAG_PATTERN =
/\A[a-z0-9][a-z0-9-]*[a-z0-9]\z|\A[a-z0-9]\z/.freeze
Instance Attribute Summary collapse
-
#brand ⇒ Object
readonly
Returns the value of attribute brand.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#jump ⇒ Object
readonly
Returns the value of attribute jump.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Location
constructor
A new instance of Location.
-
#searchable_terms(brands: {}, clients: {}) ⇒ Array<String>
Get all searchable text for this location.
-
#to_h ⇒ Hash
Convert to hash for JSON serialization.
-
#valid? ⇒ Boolean
Check if location is valid.
-
#validate ⇒ Array<String>
Validate the location.
Constructor Details
#initialize(attrs = {}) ⇒ Location
Returns a new instance of Location.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/appydave/tools/jump/location.rb', line 25 def initialize(attrs = {}) attrs = normalize_attrs(attrs) @key = attrs[:key] @path = attrs[:path] @jump = attrs[:jump] || default_jump @brand = attrs[:brand] @client = attrs[:client] @type = attrs[:type] = Array(attrs[:tags]) @description = attrs[:description] end |
Instance Attribute Details
#brand ⇒ Object (readonly)
Returns the value of attribute brand.
23 24 25 |
# File 'lib/appydave/tools/jump/location.rb', line 23 def brand @brand end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
23 24 25 |
# File 'lib/appydave/tools/jump/location.rb', line 23 def client @client end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
23 24 25 |
# File 'lib/appydave/tools/jump/location.rb', line 23 def description @description end |
#jump ⇒ Object (readonly)
Returns the value of attribute jump.
23 24 25 |
# File 'lib/appydave/tools/jump/location.rb', line 23 def jump @jump end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
23 24 25 |
# File 'lib/appydave/tools/jump/location.rb', line 23 def key @key end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
23 24 25 |
# File 'lib/appydave/tools/jump/location.rb', line 23 def path @path end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
23 24 25 |
# File 'lib/appydave/tools/jump/location.rb', line 23 def end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
23 24 25 |
# File 'lib/appydave/tools/jump/location.rb', line 23 def type @type end |
Instance Method Details
#searchable_terms(brands: {}, clients: {}) ⇒ Array<String>
Get all searchable text for this location
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/appydave/tools/jump/location.rb', line 79 def searchable_terms(brands: {}, clients: {}) terms = [key, path, type, description].compact terms.concat() # Add brand and its aliases if brand && brands[brand] terms << brand terms.concat(Array(brands[brand]['aliases'] || brands[brand][:aliases])) elsif brand terms << brand end # Add client and its aliases if client && clients[client] terms << client terms.concat(Array(clients[client]['aliases'] || clients[client][:aliases])) elsif client terms << client end terms.compact.map(&:to_s).map(&:downcase) end |
#to_h ⇒ Hash
Convert to hash for JSON serialization
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/appydave/tools/jump/location.rb', line 61 def to_h { key: key, path: path, jump: jump, brand: brand, client: client, type: type, tags: , description: description }.compact end |
#valid? ⇒ Boolean
Check if location is valid
54 55 56 |
# File 'lib/appydave/tools/jump/location.rb', line 54 def valid? validate.empty? end |
#validate ⇒ Array<String>
Validate the location
41 42 43 44 45 46 47 48 49 |
# File 'lib/appydave/tools/jump/location.rb', line 41 def validate errors = [] errors << 'Key is required' if key.nil? || key.empty? errors << "Key '#{key}' is invalid (must be lowercase alphanumeric with hyphens)" if key && !valid_key? errors << 'Path is required' if path.nil? || path.empty? errors << "Path '#{path}' is invalid (must start with ~ or /)" if path && !valid_path? errors.concat() errors end |