smartphone_finder-cli 1.0.7 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 267f0b35016f9acb28c770bcd01c980f3277166b
4
- data.tar.gz: cb1a125f7fe77c37077b0af43edd361d548f895a
2
+ SHA256:
3
+ metadata.gz: cb96a908bcfc9703dde3f8950c2119ac194905b57a679024dd5b35c68d069e6d
4
+ data.tar.gz: 296558344d6ab1b6b28d7ccce2ba6c7567e4f3ea5b84c03239fa1079f67181e9
5
5
  SHA512:
6
- metadata.gz: 60efba0114b691a6f8c00de828e7c5beaa2c1c8bbdcc95cbc88d539d86aa94b924239032827231fe988f709db9eba7ce16256f3c4539a2d86117b252956b1a94
7
- data.tar.gz: d2b82d10e7c0f7513413254e4015ec3371f0f41991b5c1d68ce16340113ddbb8cb94b39824ccd7e350d6546b06c90860804c51b8339a95b23a7be57953d721f7
6
+ metadata.gz: 8df7beb2699a0cdb2f8816b0203717ef15b7d4eb3734283ec8cb89f66ec4f7cd01ddb10f2185a4345d344d1c7d030b2b9dfdf5530211d7dc8a65bc3a4372f31d
7
+ data.tar.gz: e858ba8e92f832dc90dfc285efd55781aa9a0bc67373ee7ed3b765178b86d2f31a496a631e3b90e873ad3b83309bf7178455b60e0ecb07de40faca39318e71ed
data/.gitignore CHANGED
@@ -1,9 +1,9 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --format documentation
2
- --color
1
+ --format documentation
2
+ --color
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.13.6
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,74 +1,74 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at TODO: Write your email address. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in smartphone_finder.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smartphone_finder.gemspec
4
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 TODO: Write your name
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.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
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 CHANGED
@@ -1,43 +1,43 @@
1
- # SmartphoneFinder
2
-
3
- Welcome to Smartphone Finder Cli Application .with this Application you can search online and find your favorite
4
- Mobiles,Tabs and SmartWatches Specifications and price ranges .
5
-
6
- This App use the famous website www.gsmarena.com to Scrape the information online .
7
-
8
- ## Installation
9
-
10
- Add this line to your application's Gemfile:
11
-
12
- ```ruby
13
- gem 'smartphone_finder-cli'
14
- ```
15
-
16
- And then execute:
17
-
18
- $ bundle
19
-
20
- Or install it yourself as:
21
-
22
- $ gem install smartphone_finder-cli
23
-
24
- ## Usage
25
-
26
- Run: `smartphone_finder` after installing the gem to start cli app.
27
-
28
- ## Development
29
-
30
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
-
32
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
-
34
- ## Contributing
35
-
36
- Bug reports and pull requests are welcome on GitHub at https://github.com/alrawi90/smartphone_finder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
-
38
-
39
- ## License
40
-
41
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
42
-
43
- # smartphone_finder
1
+ # SmartphoneFinder
2
+
3
+ Welcome to Smartphone Finder Cli Application .with this Application you can search online and find your favorite
4
+ Mobiles,Tabs and SmartWatches Specifications and price ranges .
5
+
6
+ This App use the famous website www.gsmarena.com to Scrape the information online .
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'smartphone_finder-cli'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install smartphone_finder-cli
23
+
24
+ ## Usage
25
+
26
+ Run: `smartphone_finder` after installing the gem to start cli app.
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/alrawi90/smartphone_finder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
42
+
43
+ # smartphone_finder
data/Rakefile CHANGED
@@ -1,6 +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
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 CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "smartphone_finder"
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
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "smartphone_finder"
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/setup CHANGED
@@ -1,8 +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
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
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env ruby
2
- require_relative '../lib/smartphone_finder.rb'
3
- #require File.expand_path("../smartphone_finder", __FILE__)
4
- #require '../lib/smartphone_finder.rb'
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/smartphone_finder.rb'
3
+ #require File.expand_path("../smartphone_finder", __FILE__)
4
+ #require '../lib/smartphone_finder.rb'
5
5
  SmartphoneFinder::CLI.new.start
@@ -1,40 +1,39 @@
1
- module HelperMethods
2
-
3
- def obj_exist?
4
- self.class.all.detect{|obj| obj.name == self.name}
5
- end
6
- def list_all(array) #this method will print brands in 3 colomns
7
- counter=0
8
- sep= "----------------------------------------------------------------"
9
- indention=" "
10
- extra=" "
11
-
12
- object =array.max{|a, b| a.length <=> b.length}
13
- width=object.length + 5
14
- while counter <array.size
15
- counter <9 ? extra=" " : extra=""
16
- if array.size - counter >=3
17
- col_1=array[counter]; col_1_spc=indention*(width - col_1.length)
18
- col_2=array[counter+1] ;col_2_spc=indention*(width - col_2.length)
19
- col_3=array[counter+2];
20
-
21
- puts "#{counter+1}- #{extra}#{col_1}#{col_1_spc}#{counter+2}- #{extra}#{col_2}#{col_2_spc}#{counter+3}- #{extra}#{col_3}"
22
- elsif array.size - counter >=2
23
- col_1=array[counter]; col_1_spc=indention*(width - col_1.length)
24
- col_2=array[counter+1];
25
- puts "#{counter+1}- {extra}#{col_1}#{col_1_spc}#{counter+2}- #{extra}#{col_2}"
26
- elsif array.size - counter >=1
27
- col_1=array[counter];
28
- puts "#{counter+1}- #{extra}#{col_1}"
29
-
30
- end
31
- counter+=3
32
- end
33
-
34
-
35
- 2.times do
36
- puts sep*2
37
- end
38
- end
39
-
1
+ module HelperMethods
2
+
3
+ def obj_exist?
4
+ self.class.all.detect{|obj| obj.name == self.name}
5
+ end
6
+ def list_all(array) #this method will print lists in 3 colomns
7
+ counter=0
8
+ sep= "----------------------------------------------------------------"
9
+ indention=" "
10
+ extra=" "
11
+
12
+ object =array.max{|a, b| a.length <=> b.length} #get the longest list entry
13
+ width=object.length + 5
14
+ while counter <array.size
15
+ counter <9 ? extra=" " : extra=""
16
+ if array.size - counter >=3
17
+ col_1=array[counter]; col_1_spc=indention*(width - col_1.length)
18
+ col_2=array[counter+1] ;col_2_spc=indention*(width - col_2.length)
19
+ col_3=array[counter+2];
20
+ puts "#{counter+1}- #{extra}#{col_1}#{col_1_spc}#{counter+2}- #{extra}#{col_2}#{col_2_spc}#{counter+3}- #{extra}#{col_3}"
21
+ elsif array.size - counter >=2
22
+ col_1=array[counter]; col_1_spc=indention*(width - col_1.length)
23
+ col_2=array[counter+1];
24
+ puts "#{counter+1}- #{extra}#{col_1}#{col_1_spc}#{counter+2}- #{extra}#{col_2}"
25
+ elsif array.size - counter >=1
26
+ col_1=array[counter];
27
+ puts "#{counter+1}- #{extra}#{col_1}"
28
+
29
+ end
30
+ counter+=3
31
+ end
32
+
33
+
34
+ 2.times do
35
+ puts sep*2
36
+ end
37
+ end
38
+
40
39
  end
@@ -1,40 +1,40 @@
1
- require_relative '../concerns/helper_methods.rb'
2
-
3
- class SmartphoneFinder::Brand
4
- include HelperMethods
5
- extend HelperMethods
6
- @@all=[]
7
- attr_accessor :name ,:url ,:devices
8
- def initialize(name , url)
9
- @name=name
10
- @url= url
11
- @devices=[]
12
- if ! obj_exist?
13
- @@all.push(self)
14
- end
15
- end
16
- def self.find_by_name(brand_name)
17
- self.all.each do |b|
18
- if b.name.downcase==brand_name.downcase
19
- return b
20
- end
21
- end
22
- return SmartphoneFinder::Brand.new(brand_name,nil)
23
- end
24
- def self.all
25
- @@all
26
- end
27
-
28
- def add_device(device)
29
- if !self.devices.detect{|obj| obj.name == device.name}
30
- devices.push(device)
31
- end
32
- end
33
- def self.list_brands
34
- self.list_all(self.all.collect { |obj| obj.name })
35
- end
36
- def list_devices
37
- self.list_all(self.devices.collect { |obj| obj.name })
38
- end
39
-
1
+ require_relative '../concerns/helper_methods.rb'
2
+
3
+ class SmartphoneFinder::Brand
4
+ include HelperMethods
5
+ extend HelperMethods
6
+ @@all=[]
7
+ attr_accessor :name ,:url ,:devices
8
+ def initialize(name , url)
9
+ @name=name
10
+ @url= url
11
+ @devices=[]
12
+ if ! obj_exist?
13
+ @@all.push(self)
14
+ end
15
+ end
16
+ def self.find_by_name(brand_name)
17
+ self.all.each do |b|
18
+ if b.name.downcase==brand_name.downcase
19
+ return b
20
+ end
21
+ end
22
+ return SmartphoneFinder::Brand.new(brand_name,nil)
23
+ end
24
+ def self.all
25
+ @@all
26
+ end
27
+
28
+ def add_device(device)
29
+ if !self.devices.detect{|obj| obj.name == device.name}
30
+ devices.push(device)
31
+ end
32
+ end
33
+ def self.list_brands
34
+ self.list_all(self.all.collect { |obj| obj.name })
35
+ end
36
+ def list_devices
37
+ self.list_all(self.devices.collect { |obj| obj.name })
38
+ end
39
+
40
40
  end
@@ -1,163 +1,164 @@
1
- require_relative '../concerns/helper_methods.rb'
2
-
3
- class SmartphoneFinder::CLI
4
- include HelperMethods
5
- @search_results=[]
6
-
7
- attr_accessor :search_results
8
- def start
9
- welcome
10
- menu
11
- end
12
-
13
- def welcome
14
- puts ""
15
- puts "welcome to Smartphone Finder version #{SmartphoneFinder::VERSION}"
16
- end
17
- def list
18
- puts ""
19
- puts "-----------------------Main Menu------------------------------------------------------------#"
20
- puts "1- Search by brand #Enter '1' to browse brands and related devices online on gsmarena.com |"
21
- puts "2- Search by keyword #Enter '2' to search for specifed keyword online on gsmarena.com |"
22
- puts "3- Exit #Enter '3' to End application. |"
23
- puts "--------------------------------------------------------------------------------------------#"
24
- puts ""
25
- puts "choose an option please"
26
-
27
- end
28
- def search_by_brand
29
-
30
- #get and display brands
31
- show_brands
32
- #ask user to choose brand index to list relative devices
33
- puts""
34
- puts"Enter brand index to list relative devices OR Enter 'menu' to list the main menu"
35
- input=gets.strip.to_i
36
- if input>0 && input <= SmartphoneFinder::Brand.all.size
37
- #get and display devices
38
- size=show_devices(input-1)#returns devices number
39
- #choose a device and get/display device specifications
40
- puts ""
41
- show_device_spec(size,"1",input-1)
42
- elsif input > SmartphoneFinder::Brand.all.size
43
- puts ""
44
- puts "invalid brand index"
45
- search_by_brand
46
- else
47
- #puts "invalid option"
48
- list
49
- end
50
-
51
- end
52
- def show_brands
53
- #call scraper to extract brands list
54
- puts "Geting Brands ..."
55
- SmartphoneFinder::Scraper.get_brands
56
- puts ""
57
- puts "Listing all brands ..."
58
- puts ""
59
- SmartphoneFinder::Brand.list_brands
60
-
61
- end
62
- def show_devices(index)
63
- #call scraper to extract devices list
64
- SmartphoneFinder::Scraper.get_devices_by_brand(SmartphoneFinder::Brand.all[index])
65
- #listing devices .....
66
- brand=SmartphoneFinder::Brand.all[index]
67
- puts ""
68
- puts "Listing #{brand.name} devices ........"
69
- puts ""
70
- (SmartphoneFinder::Brand.all[index]).list_devices
71
- return brand.devices.size
72
- end
73
-
74
- def show_search_results
75
- puts "Listing search results ........"
76
- puts ""
77
- self.list_all(self.search_results)
78
-
79
- end
80
- def search_by_keyword
81
- puts "-------------------------------------------------"
82
- puts "Enter your desired keyword here OR Enter 'menu' to list the main menu"
83
- keyword = gets.strip
84
- if keyword=="menu"
85
- list
86
- else
87
- self.search_results= SmartphoneFinder::Scraper.get_by_keyword(keyword)
88
- if self.search_results.size>0
89
- show_search_results
90
- show_device_spec(self.search_results.size,"2")
91
- else
92
- puts "No result meet your search , please try different keyword. Would you like to try again ? Y(es) or N(o)"
93
- response=gets.strip
94
- if response.downcase=="y" || response.downcase=="yes"
95
- search_by_keyword
96
- else
97
- list
98
- end
99
- end
100
- end
101
- end
102
- def show_device_spec(size,option,index=nil)
103
- if option=="1"
104
- puts "Enter device index to show related speceifications , Enter '(B)ack' to go to brevious menu , OR Enter 'menu' to list the main menu"
105
- else
106
- puts "Enter device index to show related speceifications , Enter '(R)etry' to try different keyword , OR Enter 'menu' to list the main menu"
107
- end
108
- input_ = gets.strip
109
- index_=input_.to_i-1
110
-
111
- if input_.to_i >0 && input_.to_i <= size
112
- SmartphoneFinder::Scraper.get_device_spec(SmartphoneFinder::Device.all[index_])
113
- puts "Displaying specifications for #{(SmartphoneFinder::Device.all[index_]).name} devices ........"
114
- SmartphoneFinder::Device.all[index_].specifications.display
115
- puts ""
116
- #show navigation options
117
- puts " Enter 'menu' for main menu , Enter '(B)ack' to go to brevious list "
118
- response=gets.strip
119
- if response.downcase=="b" || response.downcase=="back"
120
-
121
- option=="2" ? show_search_results : show_devices(index)
122
- show_device_spec(size,option, index )
123
- else
124
- list
125
- end
126
- elsif input_.to_i > size
127
- puts ""
128
- puts "invalid device index"
129
- show_device_spec(size,option,index)
130
-
131
- elsif (input_.downcase=="r" || input_.downcase=="retry") && option=="2"
132
- search_by_keyword
133
- elsif (input_.downcase=="b" || input_.downcase=="back") && option=="1"
134
- search_by_brand
135
- else
136
- list
137
- end
138
- end
139
-
140
- def menu
141
- list
142
- input=nil
143
- while(input !="3")
144
- puts ""
145
- input=gets.strip
146
- if input =="1"
147
- search_by_brand
148
- elsif input =="2"
149
- search_by_keyword
150
- elsif input=="3"
151
- puts ""
152
- puts "Thank you for using Smartphone Finder"
153
- puts ""
154
- break
155
-
156
- else
157
- puts "invalid input"
158
- list
159
- end
160
- end
161
- end
162
-
1
+ require_relative '../concerns/helper_methods.rb'
2
+
3
+ class SmartphoneFinder::CLI
4
+ include HelperMethods
5
+ @search_results=[]
6
+
7
+ attr_accessor :search_results
8
+ def start
9
+ welcome
10
+ menu
11
+ end
12
+
13
+ def welcome#welcom user and display the current version
14
+ puts ""
15
+ puts "welcome to Smartphone Finder version #{SmartphoneFinder::VERSION}"
16
+ end
17
+ def list
18
+ puts ""
19
+ puts "-----------------------Main Menu------------------------------------------------------------#"
20
+ puts "1- Search by brand #Enter '1' to browse brands and related devices online on gsmarena.com |"
21
+ puts "2- Search by keyword #Enter '2' to search for specifed keyword online on gsmarena.com |"
22
+ puts "3- Exit #Enter '3' to End application. |"
23
+ puts "--------------------------------------------------------------------------------------------#"
24
+ puts ""
25
+ puts "choose an option please"
26
+
27
+ end
28
+ def search_by_brand
29
+
30
+ #get and display brands
31
+ show_brands
32
+ #ask user to choose brand index to list relative devices
33
+ puts""
34
+ puts"Enter brand index to list relative devices OR Enter 'menu' to list the main menu"
35
+ input=gets.strip.to_i
36
+ if input>0 && input <= SmartphoneFinder::Brand.all.size
37
+ #get and display devices
38
+ size=show_devices(input-1)#returns devices number
39
+ #choose a device and get/display device specifications
40
+ puts ""
41
+ show_device_spec(size,"1",input-1)
42
+ elsif input > SmartphoneFinder::Brand.all.size
43
+ puts ""
44
+ puts "invalid brand index"
45
+ search_by_brand
46
+ else
47
+ #puts "invalid option"
48
+ list
49
+ end
50
+
51
+ end
52
+ def show_brands
53
+ #call scraper to extract brands list
54
+ puts "Geting Brands ..."
55
+ SmartphoneFinder::Scraper.get_brands
56
+ puts ""
57
+ puts "Listing all brands ..."
58
+ puts ""
59
+ SmartphoneFinder::Brand.list_brands
60
+
61
+ end
62
+ def show_devices(index)
63
+ #call scraper to extract devices list
64
+ SmartphoneFinder::Scraper.get_devices_by_brand(SmartphoneFinder::Brand.all[index])
65
+ #listing devices .....
66
+ brand=SmartphoneFinder::Brand.all[index]
67
+ puts ""
68
+ puts "Listing #{brand.name} devices ........"
69
+ puts ""
70
+ (SmartphoneFinder::Brand.all[index]).list_devices
71
+ return brand.devices.size
72
+ end
73
+
74
+ def show_search_results
75
+ puts "Listing search results ........"
76
+ puts ""
77
+ self.list_all(self.search_results)
78
+
79
+ end
80
+ def search_by_keyword
81
+ puts "-------------------------------------------------"
82
+ puts "Enter your desired keyword here OR Enter 'menu' to list the main menu"
83
+ keyword = gets.strip
84
+ if keyword=="menu"
85
+ list
86
+ else
87
+ self.search_results= SmartphoneFinder::Scraper.get_by_keyword(keyword)
88
+ if self.search_results.size>0
89
+ show_search_results
90
+ show_device_spec(self.search_results.size,"2")
91
+ else
92
+ puts "No result meet your search , please try different keyword. Would you like to try again ? Y(es) or N(o)"
93
+ response=gets.strip
94
+ if response.downcase=="y" || response.downcase=="yes"
95
+ search_by_keyword
96
+ else
97
+ list
98
+ end
99
+ end
100
+ end
101
+ end
102
+ def show_device_spec(size,option,index=nil)#displaying device specifications
103
+ if option=="1"
104
+ puts "Enter device index to show related speceifications , Enter '(B)ack' to go to brevious menu , OR Enter 'menu' to list the main menu"
105
+ else
106
+ puts "Enter device index to show related speceifications , Enter '(R)etry' to try different keyword , OR Enter 'menu' to list the main menu"
107
+ end
108
+ input_ = gets.strip
109
+ index_=input_.to_i-1
110
+
111
+ if input_.to_i >0 && input_.to_i <= size
112
+ SmartphoneFinder::Scraper.get_device_spec(SmartphoneFinder::Device.all[index_])
113
+ puts ""
114
+ puts "Displaying specifications for #{(SmartphoneFinder::Device.all[index_]).name} devices ........"
115
+ SmartphoneFinder::Device.all[index_].specifications.display
116
+ puts ""
117
+ #show navigation options
118
+ puts " Enter 'menu' for main menu , Enter '(B)ack' to go to brevious list "
119
+ response=gets.strip
120
+ if response.downcase=="b" || response.downcase=="back"
121
+ #calling the correct method according to the chosen option
122
+ option=="2" ? show_search_results : show_devices(index)
123
+ show_device_spec(size,option, index )
124
+ else
125
+ list
126
+ end
127
+ elsif input_.to_i > size
128
+ puts ""
129
+ puts "invalid device index"
130
+ show_device_spec(size,option,index)
131
+
132
+ elsif (input_.downcase=="r" || input_.downcase=="retry") && option=="2"
133
+ search_by_keyword
134
+ elsif (input_.downcase=="b" || input_.downcase=="back") && option=="1"
135
+ search_by_brand
136
+ else
137
+ list
138
+ end
139
+ end
140
+
141
+ def menu
142
+ list
143
+ input=nil
144
+ while(input !="3")
145
+ puts ""
146
+ input=gets.strip
147
+ if input =="1"
148
+ search_by_brand
149
+ elsif input =="2"
150
+ search_by_keyword
151
+ elsif input=="3"
152
+ puts ""
153
+ puts "Thank you for using Smartphone Finder"
154
+ puts ""
155
+ break
156
+
157
+ else
158
+ puts "invalid input"
159
+ list
160
+ end
161
+ end
162
+ end
163
+
163
164
  end
@@ -1,23 +1,23 @@
1
- require_relative '../concerns/helper_methods.rb'
2
-
3
- class SmartphoneFinder::Device
4
- include HelperMethods
5
- extend HelperMethods
6
- @@all=[]
7
- attr_accessor :name ,:url ,:brand ,:specifications
8
- def initialize(name,url,brand=nil)
9
- @specifications=nil
10
- @name=name
11
- @url=url
12
- @brand=brand
13
- if ! obj_exist?
14
- @@all.push(self)
15
- end
16
- end
17
-
18
- def self.all
19
- @@all
20
- end
21
-
22
-
23
- end
1
+ require_relative '../concerns/helper_methods.rb'
2
+
3
+ class SmartphoneFinder::Device
4
+ include HelperMethods
5
+ extend HelperMethods
6
+ @@all=[]
7
+ attr_accessor :name ,:url ,:brand ,:specifications
8
+ def initialize(name,url,brand=nil)
9
+ @specifications=nil
10
+ @name=name
11
+ @url=url
12
+ @brand=brand
13
+ if ! obj_exist?
14
+ @@all.push(self)
15
+ end
16
+ end
17
+
18
+ def self.all
19
+ @@all
20
+ end
21
+
22
+
23
+ end
@@ -1,54 +1,55 @@
1
- class SmartphoneFinder::Scraper
2
- DOMAIN="http://gsmarena.com/"
3
-
4
-
5
- def self.get_brands
6
- html= open(DOMAIN)
7
- scrapped=Nokogiri::HTML(html)
8
- scrapped.css(".brandmenu-v2 ul li a").each do |e|
9
-
10
- SmartphoneFinder::Brand.new(e.text ,e.attribute("href").value)
11
-
12
- end
13
- end
14
- def self.get_devices_by_brand(brand)
15
- url=brand.url
16
- html= open(DOMAIN+url)
17
- scrapped=Nokogiri::HTML(html)
18
- scrapped.css(".makers ul li a").each do |a|
19
- device=SmartphoneFinder::Device.new(a.css("span").text,a.attribute("href").value,brand)
20
- brand.add_device(device)
21
- end
22
- end
23
- def self.get_device_spec(device)
24
- spec_table=""
25
- url=device.url
26
- html= open(DOMAIN+url)
27
- scrapped=Nokogiri::HTML(html)
28
- scrapped.css("#specs-list table").each do |table|
29
- spec_table=spec_table + table.css("th").text + ":\n"
30
- table.css("tr").each do |tr|
31
- spec_table=spec_table + " " + tr.css(".ttl a").text + " - " + tr.css(".nfo").text + "\n"
32
- end
33
- spec_table=spec_table + "--------------------------------------------------------------\n"
34
- end
35
- device.specifications= SmartphoneFinder::Specifications.new(device,spec_table)
36
- end
37
- def self.get_by_keyword(keyword)
38
- self.get_brands
39
- search_results=[]
40
- html = open(DOMAIN+"results.php3?sQuickSearch=yes&sName="+keyword)
41
- scrapped = Nokogiri::HTML(html)
42
- scrapped.css("div.makers ul a").each do |a|
43
- device_name_no_php=a.attribute("href").value.split("-")
44
- device_name_collector=device_name_no_php[0].split("_");
45
- brand=SmartphoneFinder::Brand.find_by_name(device_name_collector[0])
46
- device_name_collector.shift
47
- device_name=device_name_collector.join(" ")
48
- device=SmartphoneFinder::Device.new(device_name,a.attribute("href").value,brand)
49
- brand.add_device(device)
50
- search_results.push(brand.name + ": " +device_name)
51
- end
52
- search_results
53
- end
1
+ require 'open-uri'
2
+ class SmartphoneFinder::Scraper
3
+ DOMAIN="http://gsmarena.com/"
4
+
5
+
6
+ def self.get_brands
7
+ html= URI.open(DOMAIN)
8
+ scrapped=Nokogiri::HTML(html)
9
+ scrapped.css(".brandmenu-v2 ul li a").each do |e|
10
+
11
+ SmartphoneFinder::Brand.new(e.text ,e.attribute("href").value)
12
+
13
+ end
14
+ end
15
+ def self.get_devices_by_brand(brand)
16
+ url=brand.url
17
+ html= URI.open(DOMAIN+url)
18
+ scrapped=Nokogiri::HTML(html)
19
+ scrapped.css(".makers ul li a").each do |a|
20
+ device=SmartphoneFinder::Device.new(a.css("span").text,a.attribute("href").value,brand)
21
+ brand.add_device(device)
22
+ end
23
+ end
24
+ def self.get_device_spec(device)
25
+ spec_table=""
26
+ url=device.url
27
+ html= URI.open(DOMAIN+url)
28
+ scrapped=Nokogiri::HTML(html)
29
+ scrapped.css("#specs-list table").each do |table|
30
+ spec_table=spec_table + table.css("th").text + ":\n"
31
+ table.css("tr").each do |tr|
32
+ spec_table=spec_table + " " + tr.css(".ttl a").text + " - " + tr.css(".nfo").text + "\n"
33
+ end
34
+ spec_table=spec_table + "--------------------------------------------------------------\n"
35
+ end
36
+ device.specifications= SmartphoneFinder::Specifications.new(device,spec_table)
37
+ end
38
+ def self.get_by_keyword(keyword)
39
+ self.get_brands
40
+ search_results=[]
41
+ html = URI.open(DOMAIN+"results.php3?sQuickSearch=yes&sName="+keyword)
42
+ scrapped = Nokogiri::HTML(html)
43
+ scrapped.css("div.makers ul a").each do |a|
44
+ device_name_no_php=a.attribute("href").value.split("-")
45
+ device_name_collector=device_name_no_php[0].split("_");
46
+ brand=SmartphoneFinder::Brand.find_by_name(device_name_collector[0])
47
+ device_name_collector.shift
48
+ device_name=device_name_collector.join(" ")
49
+ device=SmartphoneFinder::Device.new(device_name,a.attribute("href").value,brand)
50
+ brand.add_device(device)
51
+ search_results.push(brand.name + ": " +device_name)
52
+ end
53
+ search_results
54
+ end
54
55
  end
@@ -1,10 +1,10 @@
1
- class SmartphoneFinder::Specifications
2
- attr_accessor :device ,:data
3
- def initialize(device,data)
4
- @device=device
5
- @data=data
6
- end
7
- def display
8
- puts data
9
- end
1
+ class SmartphoneFinder::Specifications
2
+ attr_accessor :device ,:data
3
+ def initialize(device,data)
4
+ @device=device
5
+ @data=data
6
+ end
7
+ def display
8
+ puts data
9
+ end
10
10
  end
@@ -1,3 +1,3 @@
1
- module SmartphoneFinder
2
- VERSION = "1.0.7"
3
- end
1
+ module SmartphoneFinder
2
+ VERSION = "1.1.0"
3
+ end
@@ -1,14 +1,14 @@
1
- require "nokogiri"
2
- require "open-uri"
3
- require_relative "smartphone_finder/version"
4
- require_relative "smartphone_finder/cli"
5
- require_relative "smartphone_finder/brand"
6
- require_relative "smartphone_finder/device"
7
- require_relative "smartphone_finder/scraper"
8
- require_relative "smartphone_finder/specifications"
9
- module SmartphoneFinder
10
- # Your code goes here...
11
- #puts "it works !"
12
-
13
-
14
- end
1
+ require "nokogiri"
2
+ require "open-uri"
3
+ require_relative "smartphone_finder/version"
4
+ require_relative "smartphone_finder/cli"
5
+ require_relative "smartphone_finder/brand"
6
+ require_relative "smartphone_finder/device"
7
+ require_relative "smartphone_finder/scraper"
8
+ require_relative "smartphone_finder/specifications"
9
+ module SmartphoneFinder
10
+ # Your code goes here...
11
+ #puts "it works !"
12
+
13
+
14
+ end
@@ -1,29 +1,29 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'smartphone_finder/version'
5
- Gem::Specification.new do |spec|
6
- #spec.name = 'smartphone_finder'
7
- spec.authors = ['Ali ALrawi']
8
- spec.email = ['ali.developer90@gmail.com']
9
- spec.description = 'Phones Specifications CLI App via scraping data online from gsmarena.com'
10
- spec.summary = 'Phones Specifications CLI App'
11
- spec.homepage = 'https://github.com/alrawi90/smartphone_finder'
12
- spec.license = 'MIT'
13
-
14
- spec.files = `git ls-files`.split($\)#['./lib/smartphone_finder']
15
-
16
- spec.executables = ["smartphone_finder"]
17
- #spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.name = "smartphone_finder-cli"
19
- spec.require_paths = ["lib", "lib/smartphone_finder"]
20
- spec.version = '1.0.7'#SmartphoneFinder::VERSION
21
-
22
- # Dependencies
23
- spec.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.8'
24
-
25
- # Dev Dependencies
26
- spec.add_development_dependency 'bundler', '~> 1.13'
27
- spec.add_development_dependency 'rake', '~> 10.0'
28
- spec.add_development_dependency 'rspec', '~> 3.0'
29
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smartphone_finder/version'
5
+ Gem::Specification.new do |spec|
6
+ #spec.name = 'smartphone_finder'
7
+ spec.authors = ['Ali ALrawi']
8
+ spec.email = ['ali.developer90@gmail.com']
9
+ spec.description = 'Phones Specifications CLI App via scraping data online from gsmarena.com'
10
+ spec.summary = 'Phones Specifications CLI App'
11
+ spec.homepage = 'https://github.com/alrawi90/smartphone_finder'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files`.split($\)#['./lib/smartphone_finder']
15
+
16
+ spec.executables = ["smartphone_finder"]
17
+ #spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.name = "smartphone_finder-cli"
19
+ spec.require_paths = ["lib", "lib/smartphone_finder"]
20
+ spec.version = SmartphoneFinder::VERSION
21
+
22
+ # Dependencies
23
+ spec.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.8'
24
+
25
+ # Dev Dependencies
26
+ spec.add_development_dependency 'bundler', '~> 1.13'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ end
@@ -1,11 +1,11 @@
1
- require "spec_helper"
2
-
3
- describe SmartphoneFinder do
4
- it "has a version number" do
5
- expect(SmartphoneFinder::VERSION).not_to be nil
6
- end
7
-
8
- it "does something useful" do
9
- expect(false).to eq(true)
10
- end
11
- end
1
+ require "spec_helper"
2
+
3
+ describe SmartphoneFinder do
4
+ it "has a version number" do
5
+ expect(SmartphoneFinder::VERSION).not_to be nil
6
+ end
7
+
8
+ it "does something useful" do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,2 @@
1
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
- require "smartphone_finder"
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require "smartphone_finder"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartphone_finder-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ali ALrawi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-20 00:00:00.000000000 Z
11
+ date: 2022-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -99,7 +99,6 @@ files:
99
99
  - lib/smartphone_finder/scraper.rb
100
100
  - lib/smartphone_finder/specifications.rb
101
101
  - lib/smartphone_finder/version.rb
102
- - smartphone_finder-cli-1.0.6.gem
103
102
  - smartphone_finder.gemspec
104
103
  - spec/smartphone_finder_spec.rb
105
104
  - spec/spec_helper.rb
@@ -107,7 +106,7 @@ homepage: https://github.com/alrawi90/smartphone_finder
107
106
  licenses:
108
107
  - MIT
109
108
  metadata: {}
110
- post_install_message:
109
+ post_install_message:
111
110
  rdoc_options: []
112
111
  require_paths:
113
112
  - lib
@@ -123,9 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
122
  - !ruby/object:Gem::Version
124
123
  version: '0'
125
124
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.4.8
128
- signing_key:
125
+ rubygems_version: 3.3.7
126
+ signing_key:
129
127
  specification_version: 4
130
128
  summary: Phones Specifications CLI App
131
129
  test_files: []
File without changes