nx-douban-celebrity 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6a010ebd6c8d70c13a84ac114437c1893d7f103d674d1cbcb4d8732c40d06a49
4
+ data.tar.gz: a51006f546d687b568fcac9cc7e484fa916484f4d41d9880496211a51182bffd
5
+ SHA512:
6
+ metadata.gz: d3ceb4a947f62de27a044f9eb2109357a95c500e88fc5303b20a1968021217f13d7668b4cce20f553e5fd41c179304a2316bc58b7d7a0f9f9628aabfa834462a
7
+ data.tar.gz: c9119e1c058cae0b304ed81597dcb62be2cf30167252efe8607f698abea02c0adf5098fa505e6f80bd86730e6eefe3bfdf9ed2d407f0c197877fcca8e838d9be
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in templates.gemspec
4
+ gemspec
@@ -0,0 +1,29 @@
1
+ # nx-douban-celebrity
2
+ > Douban celebrity.
3
+
4
+ ## installation
5
+ ```rb
6
+ # from gem
7
+ gem 'nx-douban-celebrity'
8
+ # from git
9
+ gem 'nx-douban-celebrity', git: 'git@github.com:afeiship/nx-douban-celebrity.git'
10
+ ```
11
+
12
+ ## usage
13
+ ```rb
14
+ Nx::DoubanCelebrity::hello
15
+
16
+ # hello world
17
+ ```
18
+
19
+ ## build/publish
20
+ ```shell
21
+ # build
22
+ gem build nx-douban-celebrity.gemspec
23
+
24
+ # publish
25
+ gem push nx-douban-celebrity-0.1.0.gem
26
+ ```
27
+
28
+ ## rspec
29
+ - https://rspec.info/
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,15 @@
1
+ require_relative "../lib/nx-douban-celebrity"
2
+ require "pp"
3
+
4
+ class App
5
+ def initialize
6
+ @app = Nx::DoubanCelebrity.new "https://movie.douban.com/celebrity/1393438/"
7
+ end
8
+
9
+ def start
10
+ pp @app.to_h
11
+ end
12
+ end
13
+
14
+ app = App.new
15
+ app.start
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nx-douban-celebrity"
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(__FILE__)
@@ -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,2 @@
1
+ require_relative "./nx/version"
2
+ require_relative "./nx/douban-celebrity"
@@ -0,0 +1,97 @@
1
+ require "open-uri"
2
+ require "nokogiri"
3
+
4
+ module Nx
5
+ class DoubanCelebrity
6
+ def initialize(url)
7
+ @url = url
8
+ @doc = Nokogiri::HTML(URI.open(url))
9
+ @info_list = @doc.css("#headline>.info li span")
10
+ end
11
+
12
+ def url
13
+ @url
14
+ end
15
+
16
+ def to_h
17
+ methods = (public_methods(false) - [__method__])
18
+ methods.map do |method|
19
+ [method, send(method)]
20
+ end.to_h
21
+ end
22
+
23
+ def title
24
+ @doc.css("#content>h1").text
25
+ end
26
+
27
+ # 头像
28
+ def avatar
29
+ el = @doc.css("#headline .pic img")
30
+ el.attribute("src").value
31
+ end
32
+
33
+ # 性别
34
+ def sex
35
+ el = @info_list.find do |item|
36
+ item.text.include? "性别"
37
+ end
38
+ clean_string(el.nil? ? "" : el.next.text)
39
+ end
40
+
41
+ # 星座
42
+ def zodiac
43
+ el = @info_list.find do |item|
44
+ item.text.include? "星座"
45
+ end
46
+ clean_string(el.nil? ? "" : el.next.text)
47
+ end
48
+
49
+ # 职业
50
+ def occupation
51
+ el = @info_list.find do |item|
52
+ item.text.include? "职业"
53
+ end
54
+ clean_string(el.nil? ? "" : el.next.text)
55
+ end
56
+
57
+ # 出生日期
58
+ def birthday
59
+ el = @info_list.find do |item|
60
+ item.text.include? "出生日期"
61
+ end
62
+ clean_string(el.nil? ? "" : el.next.text)
63
+ end
64
+
65
+ # 出生地
66
+ def birth_place
67
+ el = @info_list.find do |item|
68
+ item.text.include? "出生地"
69
+ end
70
+ clean_string(el.nil? ? "" : el.next.text)
71
+ end
72
+
73
+ # imdb编号
74
+ def imdb_url
75
+ el = @info_list.find do |item|
76
+ item.text.include? "imdb编号"
77
+ end
78
+ code = clean_string(el.nil? ? "" : el.next_element.text)
79
+ "https://www.imdb.com/name/#{code}"
80
+ end
81
+
82
+ # 影人简介
83
+ def summary
84
+ el = @doc.at_css("#intro > .bd")
85
+ clean_string el.inner_html
86
+ end
87
+
88
+ private
89
+
90
+ def clean_string(str)
91
+ str.tr!(":", "")
92
+ str.tr!("\n", "")
93
+ str.strip!
94
+ str.delete("  ")
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,5 @@
1
+ module Nx
2
+ class DoubanCelebrity
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nx/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nx-douban-celebrity"
8
+ spec.version = Nx::DoubanCelebrity::VERSION
9
+ spec.licenses = ["MIT"]
10
+ spec.authors = ["afeiship"]
11
+ spec.email = ["1290657123@qq.com"]
12
+
13
+ spec.summary = %q{Douban celebrity.}
14
+ spec.description = %q{Douban celebrity.}
15
+ spec.homepage = "https://github.com/afeiship/nx-douban-celebrity"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bump"
34
+ spec.add_development_dependency "bundler", "~> 1.14"
35
+ spec.add_development_dependency "rake", "~> 12.3", ">= 12.3.3"
36
+ end
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "nx-douban-celebrity",
3
+ "version": "1.0.0",
4
+ "description": "Douban celebrity.",
5
+ "directories": {
6
+ "lib": "lib"
7
+ },
8
+ "scripts": {
9
+ "clean": "rm -rf *.gem",
10
+ "test": "ruby __tests__/index.rb",
11
+ "prebuild": "bump patch --replace-in package.json",
12
+ "build": "gem build *.gemspec",
13
+ "pubpush": "gem push *.gem",
14
+ "unpublish":"gem yank nx-douban-celebrity -v '0.1.1'"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/afeiship/nx-douban-celebrity.git"
19
+ },
20
+ "author": "afei",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/afeiship/nx-douban-celebrity/issues"
24
+ },
25
+ "homepage": "https://github.com/afeiship/nx-douban-celebrity#readme"
26
+ }
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nx-douban-celebrity
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - afeiship
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bump
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 12.3.3
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '12.3'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 12.3.3
61
+ description: Douban celebrity.
62
+ email:
63
+ - 1290657123@qq.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - Gemfile
70
+ - README.md
71
+ - Rakefile
72
+ - __tests__/index.rb
73
+ - bin/console
74
+ - bin/setup
75
+ - lib/nx-douban-celebrity.rb
76
+ - lib/nx/douban-celebrity.rb
77
+ - lib/nx/version.rb
78
+ - nx-douban-celebrity.gemspec
79
+ - package.json
80
+ homepage: https://github.com/afeiship/nx-douban-celebrity
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.0.3
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Douban celebrity.
103
+ test_files: []