Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/linkedin_url_value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def regular?
def exceptional_errors(errors, attribute, _options = nil)
errors.add(attribute, @reason)
end

def to_str
@raw_value.to_s
end
end

class Regular
Expand All @@ -86,12 +90,13 @@ def self.cast(val)
return val if val.is_a?(Base)
return AsBlank.new(val) if val.blank?

val = val.to_str
valid_format = valid_linkedin_format?(val)
cleaned_url = clean_url(val)
return Regular.new(cleaned_url) if valid_format && cleaned_url.include?("https://www.linkedin.com/in/")

Exceptional.new(val)
rescue URI::InvalidURIError
rescue URI::InvalidURIError, NoMethodError
Exceptional.new(val)
end

Expand Down Expand Up @@ -132,4 +137,4 @@ def self.valid_linkedin_format?(linked_url)
end
end

require_relative "linkedin_url_value/railtie" if defined?(Rails) && defined?(Rails::Railtie)
require_relative "linkedin_url_value/railtie" if defined?(Rails::Railtie)
2 changes: 1 addition & 1 deletion linkedin_url_value.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |spec|
spec.name = "linkedin_url_value"
spec.version = "0.2.0"
spec.version = "0.2.1"
spec.authors = ["Grant Petersen-Speelman"]
spec.email = ["grant@nexl.io"]

Expand Down
6 changes: 6 additions & 0 deletions spec/linkedin_url_value_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ def cast(*args)
expect(first_cast).not_to eql(second_cast)
expect([first_cast, second_cast].uniq).to have_attributes(size: 2)
end

it "can be compared with other objects" do # rubocop:disable RSpec/NoExpectationExample
cast(cast(regular_value)).eql?(Object.new)
cast(cast(blank_value)).eql?(Object.new)
cast(cast(exceptional_value)).eql?(Object.new)
end
end
end

Expand Down
Loading