mdl_search 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 299e65371c1501cf34a8924643fce12c57547993
4
+ data.tar.gz: 237e55b5a9c8b839fa8c8868c55482da8f46c2ba
5
+ SHA512:
6
+ metadata.gz: fa6406e804be161f5072ed6f6eb5db6c3c89a198f26a82a9795fae1d5e382abfdb167e5b05cc8fea34f7b4efc363a45f0ad724e2b66e3a2f859af123cbc19d63
7
+ data.tar.gz: 2106b1a91dd18464730a47b8968415a4fc39965de042d91411359ee6b1a938964c25408b68dd4e1f90a077b37a1345a700d7a46673b988441b1acf8bd5cff775
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ vendor/bundle
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at ryu.ishikawa@howtelevision.jp. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mdl_search.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ryu Ishikawa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # MdlSearch
2
+
3
+ this gem helps you to search [material design icon](https://design.google.com/icons/).
4
+
5
+
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'mdl_search'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install mdl_search
23
+
24
+ ## Usage
25
+
26
+ ### 1. search icon
27
+ ```bash
28
+ $ mdl_search search --name [name] --group [group_name] --keywords [keyword are array]
29
+
30
+ # ex
31
+ $ mdl_search search --name bright --group device --keywords low auto
32
+
33
+ # brightness auto group: device
34
+ # brightness low group: device
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vsanna/mdl_search.
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
44
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mdl_search"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/mdl_search ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mdl_search'
4
+
5
+ MdlSearch::CLI.start # ここ追加
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,50 @@
1
+ require 'thor'
2
+
3
+ module MdlSearch
4
+ class CLI < Thor
5
+
6
+ desc 'search [--name name] [--keywords some key words]', 'search material icons by query'
7
+ option :name, type: :string
8
+ option :keywords, type: :array
9
+ option :group, type: :string
10
+ def search
11
+ query = set_query
12
+ MdlSearch.search(query).each do |icon|
13
+ name = set_color(icon.name.ljust(30, ' '), :yellow)
14
+ group = set_color(icon.group, :bold)
15
+ say "#{name}group: #{group}"
16
+ end
17
+ end
18
+
19
+ desc 'groups [query]', 'show material icons groups'
20
+ def groups(query = nil)
21
+ query = query.downcase
22
+ MdlSearch.groups_search(query).each do |g|
23
+ name = set_color(g[:name].ljust(20, ' '), :yellow)
24
+ length = set_color(g[:length].to_s.rjust(5, ' '), :bold)
25
+ say "#{name}length:#{length}"
26
+ end
27
+ end
28
+
29
+ desc 'update icons', 'show latest icons'
30
+ def update_icons_table
31
+ Updater.new.update_icons_yaml
32
+ end
33
+
34
+ desc 'update groups', 'show latest groups'
35
+ def update_groups_table
36
+ Updater.new.update_groups_yaml
37
+ end
38
+
39
+ private
40
+
41
+ def set_query
42
+ return nil if options.empty?
43
+ result = {}
44
+ result[:name] = options[:name] if options[:name]
45
+ result[:keywords] = options[:keywords] if options[:keywords]
46
+ result[:group] = options[:group] if options[:group]
47
+ result
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,55 @@
1
+ module MdlSearch
2
+ class << self
3
+
4
+ def search(query)
5
+ set_data_from_raw
6
+ Icon.where(query)
7
+ end
8
+
9
+ def groups_search(query)
10
+ set_data_from_raw
11
+
12
+ if query.nil?
13
+ Icon.groups
14
+ else
15
+ Icon.groups.select { |g| g[:name].downcase.include? query }
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def set_data_from_raw
22
+ set_groups_from_raw
23
+ set_icons_from_raw
24
+ end
25
+
26
+ def set_groups_from_raw
27
+ RAW_GROUPS_TABLE.each do |group_row|
28
+ Icon.groups << {
29
+ id: group_row['data']['id'],
30
+ name: group_row['data']['name'],
31
+ length: group_row['length']
32
+ }
33
+ end
34
+ end
35
+
36
+ def set_icons_from_raw
37
+ RAW_ICONS_TABLE.each do |icon_row|
38
+ json_row_to_icon(icon_row)
39
+ end
40
+ end
41
+
42
+ def json_row_to_icon(row)
43
+ Icon.icons << Icon.new(
44
+ row['ligature'],
45
+ row['name'],
46
+ row['codepoint'],
47
+ row['group_id'],
48
+ row['keywords'],
49
+ row['is_new']
50
+ )
51
+ end
52
+
53
+ end
54
+ end
55
+
@@ -0,0 +1,66 @@
1
+ module MdlSearch
2
+ class Icon
3
+ attr_accessor :key, :name, :codepoint, :group, :keywords, :is_new
4
+
5
+ @groups = []
6
+ @icons = []
7
+
8
+ def initialize(key, name, codepoint, group, keywords, is_new)
9
+ @key = key
10
+ @name = name
11
+ @codepoint = codepoint
12
+ @group = group
13
+ @keywords = keywords
14
+ @is_new = is_new
15
+ end
16
+
17
+ def modern_browser_key
18
+ @key
19
+ end
20
+
21
+ def classic_browser_key
22
+ "&#x#{@codepoint};"
23
+ end
24
+
25
+ def include_value?(key, query)
26
+ value_of_key = instance_variable_get "@#{key}"
27
+ if value_of_key.is_a? Array
28
+ value_of_key.any? { |v| hit_query? v, query }
29
+ else
30
+ hit_query? value_of_key, query
31
+ end
32
+ end
33
+
34
+ def hit_query?(value, query)
35
+ case query.class.name
36
+ when 'String'
37
+ value.to_s.downcase.include? query.downcase
38
+ when 'TrueClass', 'FalseClass'
39
+ value == query
40
+ when 'Array'
41
+ query.any? { |q| value.downcase.include? q.downcase }
42
+ else
43
+ false
44
+ end
45
+ end
46
+
47
+ class << self
48
+ attr_accessor :groups
49
+ attr_accessor :icons
50
+
51
+ def all
52
+ icons
53
+ end
54
+
55
+ def where(hash)
56
+ return self.all if hash.nil?
57
+ self.all.select do |icon|
58
+ hash.all? do |key, val|
59
+ icon.include_value?(key, val)
60
+ end
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,8 @@
1
+ require 'yaml'
2
+
3
+ module MdlSearch
4
+ class << self
5
+ RAW_GROUPS_TABLE = YAML.load(File.read(File.expand_path('./yaml/groups.yml')))
6
+ RAW_ICONS_TABLE = YAML.load(File.read(File.expand_path('./yaml/icons.yml')))
7
+ end
8
+ end
@@ -0,0 +1,67 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'yaml'
5
+
6
+ require 'pp'
7
+
8
+ module MdlSearch
9
+ class Searcher
10
+ attr_accessor :agent
11
+ attr_accessor :result
12
+
13
+ MDL_BASE = 'https://design.google.com'.freeze
14
+ MDL_API_SUFFIX = '/icons/data'.freeze
15
+ MDL_API_FOR_ALL_ICONS_INFO_SUFFIX = '/grid.json'.freeze
16
+
17
+ def initialize
18
+ @agent = create_agent
19
+ @result = all_icons_info_json
20
+ end
21
+
22
+ def icons_as_yaml
23
+ show_as_yaml icons
24
+ end
25
+
26
+ def groups_as_yaml
27
+ show_as_yaml groups
28
+ end
29
+
30
+ private
31
+
32
+ def data
33
+ pp @result
34
+ end
35
+
36
+
37
+ def icons
38
+ @result['icons']
39
+ end
40
+
41
+ def groups
42
+ @result['groups']
43
+ end
44
+
45
+ def show_as_yaml data
46
+ YAML.dump(data)
47
+ end
48
+
49
+ def create_agent
50
+ url = URI.parse MDL_BASE
51
+ agent = Net::HTTP.new url.host, url.port
52
+ agent.use_ssl = true
53
+ agent
54
+ end
55
+
56
+ def all_icons_info_json
57
+ res = @agent.get all_icons_info_path
58
+ json_raw = res.read_body
59
+ JSON.parse json_raw
60
+ end
61
+
62
+ def all_icons_info_path
63
+ "#{MDL_API_SUFFIX}#{MDL_API_FOR_ALL_ICONS_INFO_SUFFIX}"
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,28 @@
1
+ module MdlSearch
2
+ class Updater
3
+ attr_writer :searcher
4
+ def initialize
5
+ @searcher = Searcher.new
6
+ end
7
+
8
+ def update_icons_yaml
9
+ file_path = File.expand_path('../../../yaml/icons.yml', __FILE__)
10
+ File.open(file_path, 'w') do |file|
11
+ file.write @searcher.icons_as_yaml
12
+ end
13
+ puts 'complete updating icons yaml file... plz check it.'
14
+ end
15
+
16
+ def update_groups_yaml
17
+ file_path = File.expand_path('../../../yaml/groups.yml', __FILE__)
18
+ File.open(file_path, 'w') do |file|
19
+ file.write @searcher.groups_as_yaml
20
+ end
21
+ puts 'complete updating groups yaml file... plz check it.'
22
+ end
23
+
24
+ def groups_from_yaml
25
+ YAML.load(File.read(File.expand_path('./yaml/groups.yml')))
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module MdlSearch
2
+ VERSION = "0.1.0"
3
+ end
data/lib/mdl_search.rb ADDED
@@ -0,0 +1,26 @@
1
+ require "pry"
2
+ require "pry-byebug"
3
+
4
+ require "mdl_search/version"
5
+ require "mdl_search/raw_data"
6
+ require "mdl_search/icon"
7
+ require "mdl_search/searcher"
8
+ require "mdl_search/updater"
9
+ require "mdl_search/cli"
10
+ require "mdl_search/core"
11
+
12
+
13
+ module MdlSearch
14
+ # after all, you can use where
15
+ end
16
+
17
+ # 最終的にしたいこと
18
+ # 1. コマンドラインで検索で切る
19
+ # - group
20
+ # - keyword
21
+ # - できれば日本語対応
22
+ # - name
23
+ # 2. requireして使うこともできる
24
+ # - MdlSearch.search(name: 'hoge', keywords: ['a', 'b', 'c'])
25
+ # 3. mdl_helper用にtableを更新する機能
26
+ # - MdlSearch::IconTable.update / MdlSearch::IconTable.create
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mdl_search/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mdl_search"
8
+ spec.version = MdlSearch::VERSION
9
+ spec.authors = ["Ryu Ishikawa"]
10
+ spec.email = ["cvcl0808@gmail.com"]
11
+ spec.summary = "gem to search material icons by icon-name, group, keywords"
12
+ spec.description = "gem to search material icons by icon-name, group, keywords"
13
+ spec.homepage = "https://github.com/vsanna/mdl_search"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "thor"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "pry-byebug"
28
+ end
data/yaml/groups.yml ADDED
@@ -0,0 +1,65 @@
1
+ ---
2
+ - length: 216
3
+ data:
4
+ id: action
5
+ name: Action
6
+ - length: 4
7
+ data:
8
+ id: alert
9
+ name: Alert
10
+ - length: 80
11
+ data:
12
+ id: av
13
+ name: AV
14
+ - length: 50
15
+ data:
16
+ id: communication
17
+ name: Communication
18
+ - length: 41
19
+ data:
20
+ id: content
21
+ name: Content
22
+ - length: 52
23
+ data:
24
+ id: device
25
+ name: Device
26
+ - length: 68
27
+ data:
28
+ id: editor
29
+ name: Editor
30
+ - length: 14
31
+ data:
32
+ id: file
33
+ name: File
34
+ - length: 48
35
+ data:
36
+ id: hardware
37
+ name: Hardware
38
+ - length: 155
39
+ data:
40
+ id: image
41
+ name: Image
42
+ - length: 68
43
+ data:
44
+ id: maps
45
+ name: Maps
46
+ - length: 25
47
+ data:
48
+ id: navigation
49
+ name: Navigation
50
+ - length: 53
51
+ data:
52
+ id: notification
53
+ name: Notification
54
+ - length: 19
55
+ data:
56
+ id: places
57
+ name: Places
58
+ - length: 30
59
+ data:
60
+ id: social
61
+ name: Social
62
+ - length: 8
63
+ data:
64
+ id: toggle
65
+ name: Toggle