social_nets_db 0.0.4 → 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: f700a5cb68bd9fb80912d42a01bc422d5acacc5622b92774f8f00f3ba743d08b
4
- data.tar.gz: 30293ad58dc87169511ad0cbabe3975882e8c17457efd68d8cd54e99a8f01a83
3
+ metadata.gz: 3b07bc3f5bac88fb0cd2995b67cb093d86e3c7f9c2305862485e92bf52f4d440
4
+ data.tar.gz: 013df8d860fdfc63cd909d26636d47c0ebf25de19d6a461e2d6e2021aaa371f8
5
5
  SHA512:
6
- metadata.gz: a62fe52dc23653f6711c1b122e0575e2a0da15517ebdb3e61eb3475b89a05378ab0562b929c02827552c19f5a88e7d8a9bfb2c66666a37324788f95c86825b5e
7
- data.tar.gz: da1ed657ae79271f1ebb7254c9d43dfc9dafc6a13908913d2af7a263234965f87bf8f73b7c935df33827bd7bac06a216dc4f9bc93ec8b9d72d6213827a8caa25
6
+ metadata.gz: 97b15945fa4e52ea9b26c8306765d50025891b157bb2c4318d150aee07a25af17c50e7168cca7952813da7e29f3c4c7d6599d11abcdb2885562d569802758e39
7
+ data.tar.gz: 276f11e57a87fc304e815b114a49a549df8e12b838ad28ea9b76e5d7b22cf32da055db98b2319862b4d5ce155874f6d9c3d2089f8501208457d3cab44c874fb0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.8] - 2022-01-03
4
+
5
+ - Corrects VK domain
6
+
7
+ ## [0.0.7] - 2021-12-03
8
+
9
+ - Improves and corrects user page method
10
+ - Corrects .all method
11
+ - More documentation
12
+
13
+ ## [0.0.6] - 2021-12-03
14
+
15
+ - Corrects data source of accessor methods
16
+
17
+ ## [0.0.5] - 2021-12-03
18
+
19
+ - Corrects an error in `uids`
20
+
3
21
  ## [0.0.4] - 2021-12-03
4
22
 
5
23
  - Corrects an error in `values_for_select`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- social_nets_db (0.0.2)
4
+ social_nets_db (0.0.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Social nets DB
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/social_nets_db.svg)](https://badge.fury.io/rb/social_nets_db)
4
+
3
5
  ## Installation
4
6
 
5
7
  ```ruby
@@ -9,27 +11,24 @@ gem "social_nets_db"
9
11
 
10
12
  ## Internals
11
13
 
12
- It stores data about social nets in a Ruby hash like so:
14
+ It stores data about popular social nets, video hostings etc. in a YAML file [`db.yml`](https://github.com/sergeypedan/social-nets-db/blob/master/lib/social_nets_db/db.yml):
13
15
 
14
16
  ```yaml
15
- -
17
+ behance:
16
18
  name: Behance
17
- uid: behance
18
19
  icons:
19
- font_awesome_4: "behance"
20
+ font_awesome_4: behance
20
21
  color: "#1769ff"
21
- url: behance.com
22
+ domain: behance.com
22
23
  tags:
23
- - recruiting
24
24
  - art
25
25
  - design
26
+ - recruiting
26
27
  profile_url:
27
- by_username: https://behance.com/${username}
28
- by_account_id: "https://behance.com/${account_id}"
28
+ by_username: "https://${domain}/${uid}"
29
+ by_account_id: "https://${domain}/${uid}"
29
30
  ```
30
31
 
31
- [Peek into the source](https://github.com/sergeypedan/social-nets-db/blob/master/lib/social_net_db/db.yml).
32
-
33
32
  Everything else is just helpers around this simple DB: finders, accessors & view helpers.
34
33
 
35
34
 
@@ -47,18 +46,20 @@ ruby:
47
46
  { net_uid: "instagram", username: "dhh" },
48
47
  { net_uid: "facebook", username: "d-h-h" },
49
48
  { net_uid: "twitter", username: "d_h_h" },
50
- { net_uid: "upwork", account_id: "401298374012374" }
49
+ { net_uid: "upwork", account_id: "401298374012374" },
50
+ { net_uid: "email", username: "elon@musk.io" },
51
+ { net_uid: "website", username: "musk.io" }
51
52
  ]
52
53
 
53
54
  ul
54
55
  - accounts.each do |account|
55
- - net = SocialNetsDB.find account[:net_uid]
56
+ - net = SocialNetsDB::SocialNet.find account[:net_uid]
56
57
  li
57
- = fa_icon net.icons["font_awesome_4"], style: "color: #{net.color}"
58
+ - fa_icon_uid = net.icons["font_awesome_4"] || "link"
59
+ = fa_icon fa_icon_uid, class: "fw", style: "color: #{net.color}"
58
60
  =< link_to net.name, \
59
61
  net.user_page(username: account[:username], account_id: account[:account_id]), \
60
- target: "_blank", \
61
- rel: "noopener noreferrer"
62
+ target: "_blank", rel: "noopener noreferrer"
62
63
  ```
63
64
 
64
65
  Here the gem:
@@ -66,15 +67,13 @@ Here the gem:
66
67
  - builds the URL to user page
67
68
 
68
69
  ```ruby
69
- net.user_page(username: account[:username])
70
- # "https://facebook.com/dhh"
70
+ net.user_page(username: account[:username]) #=> "https://facebook.com/dhh"
71
71
  ```
72
72
 
73
73
  - gives you the correct name of the social net
74
74
 
75
75
  ```ruby
76
- net.name
77
- # "Facebook"
76
+ net.name #=> "Facebook"
78
77
  ```
79
78
 
80
79
  ### 2. To help building a `<select>` with social nets when storing user's account link
@@ -84,7 +83,7 @@ Here the gem:
84
83
  = f.fields_for :social_net_accounts do |sna|
85
84
  .form-group
86
85
  = sna.label :social_net_uid, class: "control-label"
87
- = sna.select :social_net_uid, SocialNetsDB.values_for_select, {}, class: "form-control"
86
+ = sna.select :social_net_uid, SocialNetsDB::SocialNet.values_for_select, {}, class: "form-control"
88
87
  ```
89
88
 
90
89
  which produces
@@ -109,19 +108,21 @@ See section “[Using with Rails](#use-with-rails)” below for more details.
109
108
 
110
109
  ## API
111
110
 
112
- ### Instance of `SocialNetsDB` class
111
+ ### Find a social net record
113
112
 
114
- Initialize an instance with social net UID.
113
+ Use either one:
115
114
 
116
115
  ```ruby
117
- social_net = SocialNetsDB.find("facebook")
116
+ social_net = SocialNetsDB::SocialNet.find("facebook")
117
+ social_net = SocialNetsDB::SocialNet.find_by(uid: "facebook")
118
+ social_net = SocialNetsDB::SocialNet.find_by_uid("facebook")
118
119
  # => #<SocialNetsDB:0x00007fddc0041b40 @uid="facebook">
119
120
  ```
120
121
 
121
122
  Which are supported UIDs?
122
123
 
123
124
  ```ruby
124
- SocialNetsDB.uids
125
+ SocialNetsDB::SocialNet.uids
125
126
  #=> [
126
127
  # "behance",
127
128
  # "dribble",
@@ -131,97 +132,45 @@ SocialNetsDB.uids
131
132
  # "habr",
132
133
  # "github",
133
134
  # "instagram",
134
- # "livejournal",
135
- # "linkedin",
136
- # "medium",
137
- # "my.mail.ru",
138
- # "odnoklassniki",
139
- # "stackoverflow",
140
- # "telegram",
141
- # "twitter",
142
- # "upwork",
143
- # "vkontakte",
144
- # "youtube"
135
+ # ...
145
136
  # ]
146
137
  ```
147
138
 
148
- If you try to initialize with an unsupported UID, and you will also get the list along with an Exception:
149
-
150
- ```ruby
151
- SocialNetsDB.find("diaspora")
152
- # ArgumentError (Social net with UID test is not supported.
153
- #
154
- # Currently supported UIDs are: behance, dribble, facebook, github, instagram, livejournal, linkedin, medium, my.mail.ru, odnoklassniki, stackoverflow, telegram, twitter, vkontakte, youtube)
155
- ```
156
-
157
- ### find_by
158
-
159
- If you don't want to rescue exceptions while initializing, you can use `find_by(uid:)` instead.
160
-
161
- It returns an instance:
162
-
163
- ```ruby
164
- SocialNetsDB.find_by(uid: "facebook")
165
- # => #<SocialNetsDB:0x00007fddc0041b40 @uid="facebook">
166
- ```
167
-
168
- or `nil`:
169
-
170
- ```ruby
171
- SocialNetsDB.find_by(uid: "blabla")
172
- # => nil
173
- ```
174
-
175
139
  ### Data
176
140
 
177
141
  ```ruby
178
- social_net.to_h
179
- # => {
180
- # name: "Facebook",
181
- # uid: "facebook",
182
- # fa_id: "facebook",
183
- # color: "crimson",
184
- # url: "https://facebook.com",
185
- # user_page: {
186
- # by_username: "https://facebook.com/${username}",
187
- # by_account_id: "https://facebook.com/${account_id}",
188
- # methods: [:account_id, :username]
189
- # }
190
- # }
142
+ social_net.to_h #=>
143
+ # {
144
+ # "name" => "Facebook",
145
+ # "icons" => { "font_awesome_4" => "facebook" },
146
+ # "color" => "#3C5A99",
147
+ # "domain" => "facebook.com",
148
+ # "tags" => ["social net"],
149
+ # "profile_url" => {
150
+ # "by_username" => "https://${domain}/${uid}",
151
+ # "by_account_id" => "https://${domain}/${uid}"
152
+ # }
153
+ # }
191
154
  ```
192
155
 
193
156
  ### Property accessors
194
157
 
195
158
  ```ruby
196
- social_net.color #=> "#3C5A99"
197
- social_net.fa_icon_id #=> "facebook"
198
- social_net.name #=> "Facebook"
199
- social_net.uid #=> "facebook"
200
- social_net.url #=> "https://facebook.com"
159
+ social_net.color #=> "#3C5A99"
160
+ social_net.name #=> "Facebook"
161
+ social_net.uid #=> "facebook"
162
+ social_net.domain #=> "facebook.com"
163
+ social_net.url #=> "https://facebook.com"
164
+ social_net.icons #=> { "font_awesome_4" => "facebook" }
201
165
  ```
202
166
 
203
167
  ### FontAwesome icon
204
168
 
205
- Assumes you have [FontAwesome](https://fontawesome.com/v4.7.0/) installed. Just builds the HTML tag.
206
-
207
169
  ```ruby
208
- social_net.fa_icon
209
- #=> <span class="fa fa-facebook" style="color: #3C5A99"></span>
170
+ social_net.icons["font_awesome_4"] #=> "facebook"
210
171
  ```
211
172
 
212
- It accepts a Hash with attributes, like Rails `tag_helper` (but not for `data: {}` — maybe later):
213
-
214
- ```ruby
215
- social_net.fa_icon(class: "fa-fw", id: "my-id", style: "margin-top: 10px")
216
- #=> <span class="fa fa-facebook fa-fw" style="color: #3C5A99; margin-top: 10px;" id="my-id"></span>
217
- ```
218
-
219
- Exporting social net brand color to `styles` attribute can be turned off by passing `color: false` Hash pair among others:
220
-
221
- ```ruby
222
- social_net.fa_icon(color: false, class: "fa-fw", id: "my-id", style: "margin-top: 10px")
223
- #=> <span class="fa fa-facebook fa-fw" style="cmargin-top: 10px;" id="my-id"></span>
224
- ```
173
+ Currently, only FontAwesome v4 icons are store. I plan adding newer version of FA, maybe other icon providers, and also SVGs.
225
174
 
226
175
  ### User's page URL
227
176
 
@@ -230,7 +179,7 @@ social_net.user_page(username: "dhh") #=> "https://facebook.com/dhh
230
179
  social_net.user_page(account_id: "id1234566789") #=> "https://facebook.com/account/id1234566789"
231
180
  ```
232
181
 
233
- If you pass a username, whild the `SocialNet` supports user page URLs only via account ids, the method call will return `nil`.
182
+ If you pass a username, while the `SocialNet` supports user page URLs only via account ids, the method call will return `nil`.
234
183
 
235
184
  You can check which is supported
236
185
 
@@ -250,13 +199,13 @@ This gem is Rails-agnostic, but you can use it in Rails like so:
250
199
  = f.fields_for :social_net_accounts do |sna|
251
200
  .form-group
252
201
  = sna.label :social_net_uid, class: "control-label"
253
- = sna.select :social_net_uid, SocialNetsDB.values_for_select, {}, class: "form-control"
202
+ = sna.select :social_net_uid, SocialNetsDB::SocialNet.values_for_select, {}, class: "form-control"
254
203
  ```
255
204
 
256
205
  because
257
206
 
258
207
  ```ruby
259
- SocialNetsDB.values_for_select
208
+ SocialNetsDB::SocialNet.values_for_select
260
209
  #=> [
261
210
  # ["Behance", "behance"],
262
211
  # ["Dribble", "dribble"],
@@ -284,16 +233,31 @@ model User < ApplicationRecord
284
233
  end
285
234
  ```
286
235
 
236
+ This would be a standard approach:
237
+
238
+ ```ruby
239
+ # model SocialNet < ApplicationRecord
240
+ # has_many :social_net_accounts
241
+ # end
242
+ ```
243
+
244
+ but instead we will use `SocialNetsDB::SocialNet` class instead of an ActiveRecord class:
245
+
246
+ ```ruby
247
+ SocialNetsDB::SocialNet.find("facebook")
248
+ SocialNetsDB::SocialNet.find_by(uid: "facebook")
249
+ ```
250
+
287
251
  ```ruby
288
252
  model SocialNetAccount < ApplicationRecord
289
253
  belongs_to :user
290
254
 
291
255
  validates :account_id, presence: true, if: Proc.new { |record| record.username.blank? }
292
- validates :social_net_uid, presence: true, inclusion: { in: SocialNetsDB.uids }
256
+ validates :social_net_uid, presence: true, inclusion: { in: SocialNetsDB::SocialNet.uids }
293
257
  validates :username, presence: true, if: Proc.new { |record| record.account_id.blank? }
294
258
 
295
259
  def social_net
296
- @social_net ||= SocialNetsDB.find(self.social_net_uid)
260
+ @social_net ||= SocialNetsDB::SocialNet.find(self.social_net_uid)
297
261
  end
298
262
 
299
263
  def user_page
@@ -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:
@@ -503,7 +503,7 @@ youtube:
503
503
  by_account_id: "https://${domain}/channel/${uid}"
504
504
 
505
505
  youtube_profile:
506
- name: YouTube
506
+ name: YouTube profile
507
507
  icons:
508
508
  font_awesome_4: "youtube"
509
509
  color: "#ff0000"
@@ -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,6 +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
15
  def initialize(uid, data)
13
16
  validate_argument_type! data, Hash
14
17
  validate_argument_type! uid, [String, Symbol]
@@ -17,34 +20,46 @@ class SocialNetsDB
17
20
 
18
21
  attr_accessor :uid
19
22
 
20
- [:color, :domain, :icons, :name].each do |method_symbol|
23
+ [:color, :domain, :icons, :name, :tags].each do |method_symbol|
21
24
  define_method(method_symbol) do
22
- to_h[method_symbol.to_s]
25
+ fallback_value = method_symbol == :tags ? [] : nil
26
+ @data.fetch(method_symbol.to_s, fallback_value)
23
27
  end
24
28
  end
25
29
 
30
+ # @return [Hash] Raw data we have on the initialized social net
31
+ #
26
32
  def to_h
27
33
  self.class.send :raw_data_for, @uid
28
34
  end
29
35
 
36
+ # @return [String] full URL of the social net
37
+ #
30
38
  def url
31
39
  "https://#{domain}"
32
40
  end
33
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
+ #
34
49
  def user_page(username: nil, account_id: nil)
35
50
  return unless page = to_h["profile_url"]
36
- return unless template = page["by_username"] || page["by_account_id"]
37
- uid = [username, account_id].select { present_str? _1 }.first or fail(ArgumentError, "Either a username or an account id must be provided")
38
-
39
- if username && page["by_username"]
40
- fail ArgumentError, "Either a username or an account id must be provided" unless present_str?(username)
41
- template.sub("${domain}", domain.to_s).sub("${uid}", username)
42
- elsif account_id && page["by_account_id"]
43
- fail ArgumentError, "Either a username or an account id must be provided" unless present_str?(account_id)
44
- template.sub("${domain}", domain.to_s).sub("${uid}", account_id)
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)
45
58
  end
46
59
  end
47
60
 
61
+ # @return [Array] available methods for bilding user page URL
62
+ #
48
63
  def user_page_methods
49
64
  ["account_id", "username"].select { |key| present_str? to_h.dig("profile_url", "by_#{key}") }
50
65
  end
@@ -55,12 +70,15 @@ class SocialNetsDB
55
70
  class << self
56
71
 
57
72
  # TODO this must be transofrmed into array of structs
73
+ # @return [Array<SocialNetsDB::SocialNet>] a list of all social nets initialized as objects
58
74
  def all
59
- RECORDS
75
+ RECORDS.map { |uid, data| new(uid, data) }
60
76
  end
61
77
 
78
+
62
79
  # @param [String] name Social network name
63
80
  # @param [String, Symbol] uid Social network UID
81
+ # @return [SocialNetsDB::SocialNet, nil]
64
82
  #
65
83
  def find_by(name: nil, uid: nil)
66
84
  return find_by_uid(uid) if present_str?(uid)
@@ -68,13 +86,19 @@ class SocialNetsDB
68
86
  fail ArgumentError, "`name:` or `uid:` must be provided. You are passing name: #{name.inspect}, uid: #{uid.inspect}"
69
87
  end
70
88
 
89
+
90
+ # @param [String] name Social network name
91
+ # @return [SocialNetsDB::SocialNet, nil]
92
+ #
71
93
  def find_by_name(name)
72
94
  validate_argument_presence! name
73
95
  return unless record = RECORDS.select { |uid, data| data["name"] == name }.first
74
96
  find_by_uid record[0]
75
97
  end
76
98
 
99
+
77
100
  # @param [String, Symbol] uid Social network UID
101
+ # @return [SocialNetsDB::SocialNet, nil]
78
102
  #
79
103
  def find_by_uid(uid)
80
104
  validate_argument_type! uid, String
@@ -96,7 +120,7 @@ class SocialNetsDB
96
120
  end
97
121
 
98
122
  def uids
99
- RECORDS.map { |uid, data| data["uid"].to_s }
123
+ RECORDS.keys.map(&:to_s)
100
124
  end
101
125
 
102
126
  def values_for_select
@@ -2,35 +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
15
-
16
- # From https://avdi.codes/recursively-symbolize-keys/
17
- #
18
- def recursively_symbolize_keys(hash)
19
- validate_argument_type! hash, Hash
20
- hash.inject({}) { |result, (key, value)|
21
- new_key = case key
22
- when String then key.to_sym
23
- else key
24
- end
25
-
26
- new_value = case value
27
- when Hash then symbolize_keys(value)
28
- else value
29
- end
30
-
31
- result[new_key] = new_value
32
- result
33
- }
34
- 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
35
15
 
36
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.4".freeze
4
+ VERSION = "0.0.8".freeze
5
5
  end
@@ -10,8 +10,6 @@ require_relative "social_nets_db/social_net"
10
10
 
11
11
  class SocialNetsDB
12
12
 
13
- # RECORDS = recursively_symbolize_keys(YAML.load_file(File.expand_path("social_nets_db/db.yml", __dir__))).freeze
14
- # RECORDS = YAML.load_file(File.expand_path("social_nets_db/db.yml", __dir__)).map { _1.transform_keys(&:to_sym) }.freeze
15
- 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
16
14
 
17
15
  end
@@ -8,19 +8,20 @@
8
8
  require_relative "lib/social_nets_db/version"
9
9
 
10
10
  Gem::Specification.new do |spec|
11
- spec.name = "social_nets_db"
12
- spec.version = SocialNetsDB::VERSION
13
- spec.authors = ["Sergey Pedan"]
14
- spec.email = ["sergey.pedan@gmail.com"]
15
- spec.license = "MIT"
16
-
17
- spec.summary = "A non-comprehensive database of social nets packed in a Ruby gem"
18
- spec.description = "#{spec.summary}. We have helpers for color, user page URL, FontAwesome icon, social net domain, some tags for grouping social nets, etc."
19
-
20
- spec.homepage = "https://github.com/sergeypedan/social-nets-db"
21
- spec.metadata = { "changelog_uri" => "https://github.com/sergeypedan/social-nets-db/blob/master/CHANGELOG.md",
22
- "homepage_uri" => spec.homepage,
23
- "source_code_uri" => "https://github.com/sergeypedan/social-nets-db.git"}
11
+ spec.name = "social_nets_db"
12
+ spec.version = SocialNetsDB::VERSION
13
+ spec.authors = ["Sergey Pedan"]
14
+ spec.email = ["sergey.pedan@gmail.com"]
15
+ spec.license = "MIT"
16
+
17
+ spec.summary = "A non-comprehensive database of social nets packed in a Ruby gem"
18
+ spec.description = "#{spec.summary}. We have helpers for color, user page URL, FontAwesome icon, social net domain, some tags for grouping social nets, etc."
19
+
20
+ spec.homepage = "https://sergeypedan.ru/open_source_projects/social-nets-db"
21
+ spec.metadata = { "changelog_uri" => "https://github.com/sergeypedan/social-nets-db/blob/master/CHANGELOG.md",
22
+ "documentation_uri" => "https://www.rubydoc.info/gems/#{spec.name}",
23
+ "homepage_uri" => spec.homepage,
24
+ "source_code_uri" => "https://github.com/sergeypedan/social-nets-db" }
24
25
 
25
26
  spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
26
27
  spec.rdoc_options = ["--charset=UTF-8"]
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.4
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-02 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
@@ -146,13 +146,14 @@ files:
146
146
  - lib/social_nets_db/tag_helper.rb
147
147
  - lib/social_nets_db/version.rb
148
148
  - social_nets_db.gemspec
149
- homepage: https://github.com/sergeypedan/social-nets-db
149
+ homepage: https://sergeypedan.ru/open_source_projects/social-nets-db
150
150
  licenses:
151
151
  - MIT
152
152
  metadata:
153
153
  changelog_uri: https://github.com/sergeypedan/social-nets-db/blob/master/CHANGELOG.md
154
- homepage_uri: https://github.com/sergeypedan/social-nets-db
155
- source_code_uri: https://github.com/sergeypedan/social-nets-db.git
154
+ documentation_uri: https://www.rubydoc.info/gems/social_nets_db
155
+ homepage_uri: https://sergeypedan.ru/open_source_projects/social-nets-db
156
+ source_code_uri: https://github.com/sergeypedan/social-nets-db
156
157
  post_install_message:
157
158
  rdoc_options:
158
159
  - "--charset=UTF-8"