Skip to content
Snippets Groups Projects
Commit 5f486c36 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

url becomes value

parent dc9ed434
No related branches found
No related tags found
No related merge requests found
class ContactDetails::Base class ContactDetails::Base
attr_accessor :url, :label attr_accessor :value, :label
def initialize(string) def initialize(string)
@string = string.to_s @string = string.to_s
return if @string.blank? return if @string.blank?
prepare_url prepare_value
prepare_label prepare_label
end end
def present? def present?
url.present? value.present?
end end
protected protected
def prepare_url def prepare_value
@url = @string.dup @value = @string.dup
end end
def prepare_label def prepare_label
......
...@@ -3,8 +3,8 @@ class ContactDetails::Email < ContactDetails::Base ...@@ -3,8 +3,8 @@ class ContactDetails::Email < ContactDetails::Base
protected protected
def prepare_url def prepare_value
@url = "#{PREFIX}#{@string}" @value = "#{PREFIX}#{@string}"
end end
end end
\ No newline at end of file
...@@ -3,14 +3,14 @@ class ContactDetails::Phone < ContactDetails::Base ...@@ -3,14 +3,14 @@ class ContactDetails::Phone < ContactDetails::Base
protected protected
def prepare_url def prepare_value
super super
@url.remove! ' ' @value.remove! ' '
@url.remove! '.' @value.remove! '.'
@url = "#{PREFIX}#{@url}" @value = "#{PREFIX}#{@value}"
end end
def prepare_label def prepare_label
@label = @url.remove PREFIX @label = @value.remove PREFIX
end end
end end
\ No newline at end of file
...@@ -4,16 +4,16 @@ class ContactDetails::Twitter < ContactDetails::Base ...@@ -4,16 +4,16 @@ class ContactDetails::Twitter < ContactDetails::Base
protected protected
def prepare_url def prepare_value
super super
@url.remove! DOMAIN if @url.start_with? DOMAIN @value.remove! DOMAIN if @value.start_with? DOMAIN
@url.remove! URL if @url.start_with? URL @value.remove! URL if @value.start_with? URL
@url.delete_suffix! '/' @value.delete_suffix! '/'
@url.delete_prefix! '/' @value.delete_prefix! '/'
@url = "#{URL}#{@url}" @value = "#{URL}#{@value}"
end end
def prepare_label def prepare_label
@label = @url.remove URL @label = @value.remove URL
end end
end end
\ No newline at end of file
...@@ -3,12 +3,12 @@ class ContactDetails::Website < ContactDetails::Base ...@@ -3,12 +3,12 @@ class ContactDetails::Website < ContactDetails::Base
protected protected
def prepare_url def prepare_value
super super
@url = "#{PROTOCOL}#{@url}" unless @url.start_with? PROTOCOL @value = "#{PROTOCOL}#{@value}" unless @value.start_with? PROTOCOL
end end
def prepare_label def prepare_label
@label = @url.remove PROTOCOL @label = @value.remove PROTOCOL
end end
end end
\ No newline at end of file
...@@ -4,5 +4,5 @@ if detail.present? ...@@ -4,5 +4,5 @@ if detail.present?
%> %>
<%= variable %>: <%= variable %>:
label: <%= detail.label %> label: <%= detail.label %>
url: <%= detail.url %> value: <%= detail.value %>
<% end %> <% end %>
\ No newline at end of file
...@@ -5,85 +5,85 @@ class ContactDetailsTest < ActiveSupport::TestCase ...@@ -5,85 +5,85 @@ class ContactDetailsTest < ActiveSupport::TestCase
test "country nil" do test "country nil" do
detail = ContactDetails::Country.new nil detail = ContactDetails::Country.new nil
assert_nil detail.label assert_nil detail.label
assert_nil detail.url assert_nil detail.value
end end
test "country FR" do test "country FR" do
detail = ContactDetails::Country.new 'FR' detail = ContactDetails::Country.new 'FR'
assert_equal 'France', detail.label assert_equal 'France', detail.label
assert_equal 'FR', detail.url assert_equal 'FR', detail.value
end end
test "email nil" do test "email nil" do
detail = ContactDetails::Email.new nil detail = ContactDetails::Email.new nil
assert_nil detail.label assert_nil detail.label
assert_nil detail.url assert_nil detail.value
end end
test "email arnaud.levy@noesya.coop" do test "email arnaud.levy@noesya.coop" do
detail = ContactDetails::Email.new 'arnaud.levy@noesya.coop' detail = ContactDetails::Email.new 'arnaud.levy@noesya.coop'
assert_equal 'arnaud.levy@noesya.coop', detail.label assert_equal 'arnaud.levy@noesya.coop', detail.label
assert_equal 'mailto:arnaud.levy@noesya.coop', detail.url assert_equal 'mailto:arnaud.levy@noesya.coop', detail.value
end end
test "twitter nil" do test "twitter nil" do
detail = ContactDetails::Twitter.new nil detail = ContactDetails::Twitter.new nil
assert_nil detail.label assert_nil detail.label
assert_nil detail.url assert_nil detail.value
end end
test "twitter handle" do test "twitter handle" do
detail = ContactDetails::Twitter.new 'arnaudlevy' detail = ContactDetails::Twitter.new 'arnaudlevy'
assert_equal 'arnaudlevy', detail.label assert_equal 'arnaudlevy', detail.label
assert_equal 'https://twitter.com/arnaudlevy', detail.url assert_equal 'https://twitter.com/arnaudlevy', detail.value
end end
test "mastodon nil" do test "mastodon nil" do
detail = ContactDetails::Mastodon.new nil detail = ContactDetails::Mastodon.new nil
assert_nil detail.label assert_nil detail.label
assert_nil detail.url assert_nil detail.value
end end
test "mastodon mastodon.social/@arnaudlevy" do test "mastodon mastodon.social/@arnaudlevy" do
detail = ContactDetails::Mastodon.new 'mastodon.social/@arnaudlevy' detail = ContactDetails::Mastodon.new 'mastodon.social/@arnaudlevy'
assert_equal 'mastodon.social/@arnaudlevy', detail.label assert_equal 'mastodon.social/@arnaudlevy', detail.label
assert_equal 'https://mastodon.social/@arnaudlevy', detail.url assert_equal 'https://mastodon.social/@arnaudlevy', detail.value
end end
test "mastodon https://mastodon.social/@arnaudlevy" do test "mastodon https://mastodon.social/@arnaudlevy" do
detail = ContactDetails::Mastodon.new 'https://mastodon.social/@arnaudlevy' detail = ContactDetails::Mastodon.new 'https://mastodon.social/@arnaudlevy'
assert_equal 'mastodon.social/@arnaudlevy', detail.label assert_equal 'mastodon.social/@arnaudlevy', detail.label
assert_equal 'https://mastodon.social/@arnaudlevy', detail.url assert_equal 'https://mastodon.social/@arnaudlevy', detail.value
end end
test "twitter twitter.com/arnaudlevy" do test "twitter twitter.com/arnaudlevy" do
detail = ContactDetails::Twitter.new 'twitter.com/arnaudlevy' detail = ContactDetails::Twitter.new 'twitter.com/arnaudlevy'
assert_equal 'arnaudlevy', detail.label assert_equal 'arnaudlevy', detail.label
assert_equal 'https://twitter.com/arnaudlevy', detail.url assert_equal 'https://twitter.com/arnaudlevy', detail.value
end end
test "twitter https://twitter.com/arnaudlevy" do test "twitter https://twitter.com/arnaudlevy" do
detail = ContactDetails::Twitter.new 'https://twitter.com/arnaudlevy' detail = ContactDetails::Twitter.new 'https://twitter.com/arnaudlevy'
assert_equal 'arnaudlevy', detail.label assert_equal 'arnaudlevy', detail.label
assert_equal 'https://twitter.com/arnaudlevy', detail.url assert_equal 'https://twitter.com/arnaudlevy', detail.value
end end
test "website nil" do test "website nil" do
detail = ContactDetails::Website.new nil detail = ContactDetails::Website.new nil
assert_nil detail.label assert_nil detail.label
assert_nil detail.url assert_nil detail.value
end end
test "website www.noesya.coop" do test "website www.noesya.coop" do
detail = ContactDetails::Website.new 'www.noesya.coop' detail = ContactDetails::Website.new 'www.noesya.coop'
assert_equal 'www.noesya.coop', detail.label assert_equal 'www.noesya.coop', detail.label
assert_equal 'https://www.noesya.coop', detail.url assert_equal 'https://www.noesya.coop', detail.value
end end
test "website https://www.noesya.coop" do test "website https://www.noesya.coop" do
detail = ContactDetails::Website.new 'https://www.noesya.coop' detail = ContactDetails::Website.new 'https://www.noesya.coop'
assert_equal 'www.noesya.coop', detail.label assert_equal 'www.noesya.coop', detail.label
assert_equal 'https://www.noesya.coop', detail.url assert_equal 'https://www.noesya.coop', detail.value
end end
end end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment