social_nets_db 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16056e32bc256d743a1b7fa14d16d714d242ee3a3d4ee106d71d51e6bed03c58
4
- data.tar.gz: e91524ea8abd15b0f24584645605398ffb6026039fa082a240d04e719850f7df
3
+ metadata.gz: 3b07bc3f5bac88fb0cd2995b67cb093d86e3c7f9c2305862485e92bf52f4d440
4
+ data.tar.gz: 013df8d860fdfc63cd909d26636d47c0ebf25de19d6a461e2d6e2021aaa371f8
5
5
  SHA512:
6
- metadata.gz: 72bdf3a625923ec900dcc76d98dd2e01932848b003b51dfcc3fc0589484086a5a2bafb6f71c9a9120e33b410c180dc53837a681b79030879a01016d3d6bb3285
7
- data.tar.gz: a2fa51dad61a848b70cc82e923ab19b4c41b435487cff99f5620e4ff3c25e0f41d845513bfaffcd0df60ba60c7d7cd0246c36fc9979455846d620ce9fc4786a9
6
+ metadata.gz: 97b15945fa4e52ea9b26c8306765d50025891b157bb2c4318d150aee07a25af17c50e7168cca7952813da7e29f3c4c7d6599d11abcdb2885562d569802758e39
7
+ data.tar.gz: 276f11e57a87fc304e815b114a49a549df8e12b838ad28ea9b76e5d7b22cf32da055db98b2319862b4d5ce155874f6d9c3d2089f8501208457d3cab44c874fb0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.8] - 2022-01-03
4
+
5
+ - Corrects VK domain
6
+
3
7
  ## [0.0.7] - 2021-12-03
4
8
 
5
9
  - Improves and corrects user page method
data/README.md CHANGED
@@ -122,7 +122,7 @@ social_net = SocialNetsDB::SocialNet.find_by_uid("facebook")
122
122
  Which are supported UIDs?
123
123
 
124
124
  ```ruby
125
- SocialNetsDB.uids
125
+ SocialNetsDB::SocialNet.uids
126
126
  #=> [
127
127
  # "behance",
128
128
  # "dribble",
@@ -253,7 +253,7 @@ model SocialNetAccount < ApplicationRecord
253
253
  belongs_to :user
254
254
 
255
255
  validates :account_id, presence: true, if: Proc.new { |record| record.username.blank? }
256
- validates :social_net_uid, presence: true, inclusion: { in: SocialNetsDB.uids }
256
+ validates :social_net_uid, presence: true, inclusion: { in: SocialNetsDB::SocialNet.uids }
257
257
  validates :username, presence: true, if: Proc.new { |record| record.account_id.blank? }
258
258
 
259
259
  def social_net
@@ -483,7 +483,7 @@ vkontakte:
483
483
  icons:
484
484
  font_awesome_4: "vk"
485
485
  color: "#45668e"
486
- domain: vkontakte.com
486
+ domain: vk.com
487
487
  tags:
488
488
  - social net
489
489
  profile_url:
@@ -2,44 +2,44 @@
2
2
 
3
3
  module FnValidations
4
4
 
5
- module_function
5
+ module_function
6
6
 
7
- def validate_argument_type! argument, permitted_types
8
- types = Array(permitted_types)
9
- type_names = types.map { |klass| "`#{klass}`" }.join(" or ")
10
- valid = types.any? { |type| argument.is_a? type }
11
- message = "#{type_names} is expected, you pass a `#{argument.class}` (#{argument})"
12
- fail TypeError, message unless valid
13
- argument
14
- end
7
+ def validate_argument_type! argument, permitted_types
8
+ types = Array(permitted_types)
9
+ type_names = types.map { |klass| "`#{klass}`" }.join(" or ")
10
+ valid = types.any? { |type| argument.is_a? type }
11
+ message = "#{type_names} is expected, you pass a `#{argument.class}` (#{argument})"
12
+ fail TypeError, message unless valid
13
+ argument
14
+ end
15
15
 
16
- def validate_collection_item_types! collection, permitted_types
17
- types = Array(permitted_types)
18
- type_names = types.map { |name| "`#{name}`" }.join(" or ")
19
- valid = collection.all? { |item| types.include?(item.class) }
20
- message = "#{type_names} is expected, one the items you pass is of incorrect type"
21
- fail TypeError, message unless valid
22
- collection
23
- end
16
+ def validate_collection_item_types! collection, permitted_types
17
+ types = Array(permitted_types)
18
+ type_names = types.map { |name| "`#{name}`" }.join(" or ")
19
+ valid = collection.all? { |item| types.include?(item.class) }
20
+ message = "#{type_names} is expected, one the items you pass is of incorrect type"
21
+ fail TypeError, message unless valid
22
+ collection
23
+ end
24
24
 
25
- def validate_argument_boolean! argument
26
- validate_argument_type! argument, [TrueClass, FalseClass]
27
- end
25
+ def validate_argument_boolean! argument
26
+ validate_argument_type! argument, [TrueClass, FalseClass]
27
+ end
28
28
 
29
- def validate_argument_presence! argument
30
- validate_argument_type! argument, [String, Symbol]
31
- return argument if argument.is_a?(Symbol)
32
- message = "You must pass a non-empty String, you are passing #{argument.inspect}"
33
- fail ArgumentError, message unless argument.is_a?(String) && argument != ""
34
- argument
35
- end
29
+ def validate_argument_presence! argument
30
+ validate_argument_type! argument, [String, Symbol]
31
+ return argument if argument.is_a?(Symbol)
32
+ message = "You must pass a non-empty String, you are passing #{argument.inspect}"
33
+ fail ArgumentError, message unless argument.is_a?(String) && argument != ""
34
+ argument
35
+ end
36
36
 
37
- def validate_argument_positive! argument
38
- validate_argument_type! argument, Numeric
39
- message = "You must pass a positive value, you pass #{argument.inspect}"
40
- fail ArgumentError, message unless argument.positive?
41
- argument
42
- end
37
+ def validate_argument_positive! argument
38
+ validate_argument_type! argument, Numeric
39
+ message = "You must pass a positive value, you pass #{argument.inspect}"
40
+ fail ArgumentError, message unless argument.positive?
41
+ argument
42
+ end
43
43
 
44
44
  end
45
45
 
@@ -9,9 +9,9 @@ class SocialNetsDB
9
9
  extend FnValidations
10
10
  include FnValidations
11
11
 
12
- # @param [String, Symbol] uid Social net UID (which must be among the top-level keys in db.yml)
13
- # @param [Hash] data
14
- #
12
+ # @param [String, Symbol] uid Social net UID (which must be among the top-level keys in db.yml)
13
+ # @param [Hash] data
14
+ #
15
15
  def initialize(uid, data)
16
16
  validate_argument_type! data, Hash
17
17
  validate_argument_type! uid, [String, Symbol]
@@ -20,46 +20,46 @@ class SocialNetsDB
20
20
 
21
21
  attr_accessor :uid
22
22
 
23
- [:color, :domain, :icons, :name, :tags].each do |method_symbol|
24
- define_method(method_symbol) do
25
- fallback_value = method_symbol == :tags ? [] : nil
26
- @data.fetch(method_symbol.to_s, fallback_value)
27
- end
28
- end
23
+ [:color, :domain, :icons, :name, :tags].each do |method_symbol|
24
+ define_method(method_symbol) do
25
+ fallback_value = method_symbol == :tags ? [] : nil
26
+ @data.fetch(method_symbol.to_s, fallback_value)
27
+ end
28
+ end
29
29
 
30
- # @return [Hash] Raw data we have on the initialized social net
31
- #
30
+ # @return [Hash] Raw data we have on the initialized social net
31
+ #
32
32
  def to_h
33
33
  self.class.send :raw_data_for, @uid
34
34
  end
35
35
 
36
- # @return [String] full URL of the social net
37
- #
36
+ # @return [String] full URL of the social net
37
+ #
38
38
  def url
39
39
  "https://#{domain}"
40
40
  end
41
41
 
42
- # @return [String] full URL of user’s page in the social net
43
- # @param [String, Symbol, Integer] username
44
- # @param [String, Symbol, Integer] username
45
- # @example
46
- # SocialNetsDB::SocialNet.find("facebook").user_page(username: "dhh")
47
- # #=> "https://facebook.com/dhh"
48
- #
42
+ # @return [String] full URL of user’s page in the social net
43
+ # @param [String, Symbol, Integer] username
44
+ # @param [String, Symbol, Integer] username
45
+ # @example
46
+ # SocialNetsDB::SocialNet.find("facebook").user_page(username: "dhh")
47
+ # #=> "https://facebook.com/dhh"
48
+ #
49
49
  def user_page(username: nil, account_id: nil)
50
50
  return unless page = to_h["profile_url"]
51
- fail(ArgumentError, "Either a username or an account id must be provided") if [username, account_id].none?
52
- if username && page["by_username"]
53
- validate_argument_type! username, [String, Symbol, Integer]
54
- page["by_username"].sub("${domain}", domain.to_s).sub("${uid}", username.to_s)
55
- elsif account_id && page["by_account_id"]
56
- validate_argument_type! account_id, [String, Symbol, Integer]
57
- page["by_account_id"].sub("${domain}", domain.to_s).sub("${uid}", account_id.to_s)
58
- end
51
+ fail(ArgumentError, "Either a username or an account id must be provided") if [username, account_id].none?
52
+ if username && page["by_username"]
53
+ validate_argument_type! username, [String, Symbol, Integer]
54
+ page["by_username"].sub("${domain}", domain.to_s).sub("${uid}", username.to_s)
55
+ elsif account_id && page["by_account_id"]
56
+ validate_argument_type! account_id, [String, Symbol, Integer]
57
+ page["by_account_id"].sub("${domain}", domain.to_s).sub("${uid}", account_id.to_s)
58
+ end
59
59
  end
60
60
 
61
- # @return [Array] available methods for bilding user page URL
62
- #
61
+ # @return [Array] available methods for bilding user page URL
62
+ #
63
63
  def user_page_methods
64
64
  ["account_id", "username"].select { |key| present_str? to_h.dig("profile_url", "by_#{key}") }
65
65
  end
@@ -70,7 +70,7 @@ class SocialNetsDB
70
70
  class << self
71
71
 
72
72
  # TODO this must be transofrmed into array of structs
73
- # @return [Array<SocialNetsDB::SocialNet>] a list of all social nets initialized as objects
73
+ # @return [Array<SocialNetsDB::SocialNet>] a list of all social nets initialized as objects
74
74
  def all
75
75
  RECORDS.map { |uid, data| new(uid, data) }
76
76
  end
@@ -78,7 +78,7 @@ class SocialNetsDB
78
78
 
79
79
  # @param [String] name Social network name
80
80
  # @param [String, Symbol] uid Social network UID
81
- # @return [SocialNetsDB::SocialNet, nil]
81
+ # @return [SocialNetsDB::SocialNet, nil]
82
82
  #
83
83
  def find_by(name: nil, uid: nil)
84
84
  return find_by_uid(uid) if present_str?(uid)
@@ -87,9 +87,9 @@ class SocialNetsDB
87
87
  end
88
88
 
89
89
 
90
- # @param [String] name Social network name
91
- # @return [SocialNetsDB::SocialNet, nil]
92
- #
90
+ # @param [String] name Social network name
91
+ # @return [SocialNetsDB::SocialNet, nil]
92
+ #
93
93
  def find_by_name(name)
94
94
  validate_argument_presence! name
95
95
  return unless record = RECORDS.select { |uid, data| data["name"] == name }.first
@@ -98,7 +98,7 @@ class SocialNetsDB
98
98
 
99
99
 
100
100
  # @param [String, Symbol] uid Social network UID
101
- # @return [SocialNetsDB::SocialNet, nil]
101
+ # @return [SocialNetsDB::SocialNet, nil]
102
102
  #
103
103
  def find_by_uid(uid)
104
104
  validate_argument_type! uid, String
@@ -2,15 +2,15 @@
2
2
 
3
3
  module Support
4
4
 
5
- extend FnValidations
5
+ extend FnValidations
6
6
 
7
- # Direct analogue of Rails' `String#present?`
8
- #
9
- # @return [Boolean] is the passed argument is a non-empty String
10
- # @param arg [Any] the thing to check
11
- #
12
- def present_str?(arg)
13
- arg.is_a?(String) && arg != ""
14
- end
7
+ # Direct analogue of Rails' `String#present?`
8
+ #
9
+ # @return [Boolean] is the passed argument is a non-empty String
10
+ # @param arg [Any] the thing to check
11
+ #
12
+ def present_str?(arg)
13
+ arg.is_a?(String) && arg != ""
14
+ end
15
15
 
16
16
  end
@@ -4,33 +4,33 @@ require_relative "support"
4
4
 
5
5
  module TagHelper
6
6
 
7
- include Support
8
-
9
- def tag_attributes_to_s(options)
10
- fail ArgumentError, "A Hash must be passed, you pass #{options.class}: #{options.inspect}" unless options.is_a? Hash
11
- options.map { |pair| stringify_pair(*pair) }
12
- .reject { |stringified_attribute| [nil, ""].include?(stringified_attribute) }
13
- .join(" ")
14
- end
15
-
16
- private def stringify_pair(attribute_name, attribute_value)
17
- str_value = stringify_value(attribute_value)
18
- return "" if [nil, ""].include? str_value
19
- "#{attribute_name}=\"#{str_value}\""
20
- end
21
-
22
- private def stringify_value(value)
23
- value.is_a?(Array) ? value.join(" ") : value.to_s
24
- end
25
-
26
- def merge_style_values(existing:, incoming:)
27
- return existing unless present_str? incoming
28
- [existing, "#{incoming};"].join("; ").gsub(";;", ";")
29
- end
30
-
31
- def merge_class_values(existing:, incoming:)
32
- return existing unless present_str? incoming
33
- [existing, incoming]
34
- end
7
+ include Support
8
+
9
+ def tag_attributes_to_s(options)
10
+ fail ArgumentError, "A Hash must be passed, you pass #{options.class}: #{options.inspect}" unless options.is_a? Hash
11
+ options.map { |pair| stringify_pair(*pair) }
12
+ .reject { |stringified_attribute| [nil, ""].include?(stringified_attribute) }
13
+ .join(" ")
14
+ end
15
+
16
+ private def stringify_pair(attribute_name, attribute_value)
17
+ str_value = stringify_value(attribute_value)
18
+ return "" if [nil, ""].include? str_value
19
+ "#{attribute_name}=\"#{str_value}\""
20
+ end
21
+
22
+ private def stringify_value(value)
23
+ value.is_a?(Array) ? value.join(" ") : value.to_s
24
+ end
25
+
26
+ def merge_style_values(existing:, incoming:)
27
+ return existing unless present_str? incoming
28
+ [existing, "#{incoming};"].join("; ").gsub(";;", ";")
29
+ end
30
+
31
+ def merge_class_values(existing:, incoming:)
32
+ return existing unless present_str? incoming
33
+ [existing, incoming]
34
+ end
35
35
 
36
36
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SocialNetsDB
4
- VERSION = "0.0.7".freeze
4
+ VERSION = "0.0.8".freeze
5
5
  end
@@ -10,6 +10,6 @@ require_relative "social_nets_db/social_net"
10
10
 
11
11
  class SocialNetsDB
12
12
 
13
- RECORDS = YAML.load_file(File.expand_path("social_nets_db/db.yml", __dir__)).freeze
13
+ RECORDS = YAML.load_file(File.expand_path("social_nets_db/db.yml", __dir__)).freeze
14
14
 
15
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_nets_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Pedan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-03 00:00:00.000000000 Z
11
+ date: 2022-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler