kajian 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +21 -0
- data/README.md +96 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/kajian.gemspec +21 -0
- data/lib/kajian.rb +31 -0
- data/lib/kajian/adapter.rb +29 -0
- data/lib/kajian/adapter/jadwal_kajian.json +55 -0
- data/lib/kajian/adapter/jadwal_kajian.rb +50 -0
- data/lib/kajian/fungsi_bantu.rb +26 -0
- data/lib/kajian/koleksi_adapter.rb +29 -0
- data/lib/kajian/makro.rb +189 -0
- data/lib/kajian/version.rb +3 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f1ebed3e1cb139a9c2029bf4e9fc664c5ff482cc
|
4
|
+
data.tar.gz: fc6f259d249a41e3d6fe018cad10fa8b1dddfb8c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: feeb22ce0e1643bf02814aa530290215d66ad912a469ea44e696d70f4f36ca345aba1b603422a5019d3ef72c54d2b804d75fcce06a89261e5545744c7e51ccf5
|
7
|
+
data.tar.gz: f0e82ad4036f2be42cc3907e73440fa557cfcccb7dbd608ef91d9185f07b39fab100b798e343366b03c358d39f58493046956a0ca6a18cc01364d449284a9dfb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in kajian.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'nokogiri', '~> 1.8'
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'bundler', '~> 1.14'
|
10
|
+
gem 'rake', '~> 12.1'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :development, :test do
|
14
|
+
gem 'pry', '~> 0.10'
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Adrian Setyadi
|
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,96 @@
|
|
1
|
+
# Kajian
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/kajian.svg)](https://rubygems.org/gems/kajian)
|
4
|
+
|
5
|
+
Pustaka ruby untuk mengekstrak data acara kajian Islam dari berbagai situs di
|
6
|
+
Indonesia. Dengan menggunakan DSL (_Domain Specific Language_), mudah untuk
|
7
|
+
membuat adapter untuk situs-situs lain yang akan diekstrak data acara kajiannya.
|
8
|
+
|
9
|
+
Gem ini mengikutsertakan sebuah adapter untuk situs
|
10
|
+
[Jadwal Kajian](http://jadwalkajian.com) dengan simbol adapter `:jadwal_kajian`.
|
11
|
+
|
12
|
+
|
13
|
+
## Pemasangan
|
14
|
+
|
15
|
+
Tambahkan baris berikut ini pada Gemfile Anda:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'kajian'
|
19
|
+
```
|
20
|
+
|
21
|
+
Lalu jalankan:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Atau Anda pasang sendiri seperti ini:
|
26
|
+
|
27
|
+
$ gem install kajian
|
28
|
+
|
29
|
+
|
30
|
+
## Penggunaan
|
31
|
+
|
32
|
+
Jangan lupa `require` sebelum melihat kajian.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'kajian'
|
36
|
+
```
|
37
|
+
|
38
|
+
|
39
|
+
Lihat semua kajian
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Kajian.lihat(:semua).semua
|
43
|
+
```
|
44
|
+
|
45
|
+
|
46
|
+
Lihat semua kajian untuk daerah/kota "Bekasi"
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
Kajian.lihat(:semua).bekasi
|
50
|
+
```
|
51
|
+
|
52
|
+
|
53
|
+
Lihat semua kajian yang dipublikasikan melalui situs jadwal kajian
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
Kajian.lihat(:jadwal_kajian).semua
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
Lihat semua kajian yang dipublikasikan melalui situs jadwal kajian
|
61
|
+
daerah/kota "Tangerang"
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
Kajian.lihat(:jadwal_kajian).tangerang
|
65
|
+
```
|
66
|
+
|
67
|
+
|
68
|
+
Tambah adapter lain, contoh [Kajian Muslim](https://kajianmuslim.com)
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
require 'kajian/adapter/kajian_muslim'
|
72
|
+
|
73
|
+
Kajian.lihat(:kajian_muslim).malang
|
74
|
+
|
75
|
+
Kajian.lihat(:jadwal_kajian, :kajian_muslim).jakarta
|
76
|
+
|
77
|
+
Kajian.lihat(:semua).bandung
|
78
|
+
```
|
79
|
+
|
80
|
+
|
81
|
+
## TODO
|
82
|
+
|
83
|
+
* Dokumentasi cara membuat adapter kajian dengan menggunakan DSL Kajian
|
84
|
+
* Pencarian acara kajian berdasarkan isi kolom (termasuk tanggal) yang efisien.
|
85
|
+
* Sortir berdasarkan kolom.
|
86
|
+
* Pengecualian adapter.
|
87
|
+
|
88
|
+
|
89
|
+
## Kontribusi
|
90
|
+
|
91
|
+
Laporan _bug_ dan _pull request_ dapat diajukan melalui Github https://github.com/styd/kajian.
|
92
|
+
|
93
|
+
|
94
|
+
## Lisensi
|
95
|
+
|
96
|
+
Gem ini tersedia sebagai _open source_ sesuai ketentuan [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "kajian"
|
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__)
|
data/bin/setup
ADDED
data/kajian.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kajian/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kajian"
|
8
|
+
spec.version = Kajian::VERSION
|
9
|
+
spec.authors = ["Adrian Setyadi"]
|
10
|
+
spec.email = ["adrian@setyadi.pro"]
|
11
|
+
spec.summary = %q{Pustaka ruby untuk mengekstrak data acara kajian Islam dari berbagai situs di Indonesia.}
|
12
|
+
spec.description = %q{Pustaka ruby untuk mengekstrak data acara kajian Islam dari berbagai situs di Indonesia. Dengan menggunakan DSL (Domain Specific Language), mudah untuk menambahkan situs-situs lain untuk diekstrak data acara kajiannya.}
|
13
|
+
spec.homepage = "https://github.com/styd/kajian"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
end
|
data/lib/kajian.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "kajian/version"
|
2
|
+
require "kajian/fungsi_bantu"
|
3
|
+
require "kajian/makro"
|
4
|
+
require "kajian/koleksi_adapter"
|
5
|
+
require "kajian/adapter"
|
6
|
+
require "kajian/adapter/jadwal_kajian"
|
7
|
+
|
8
|
+
module Kajian
|
9
|
+
TidakAdaAdapter = Class.new(StandardError)
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def adapter
|
13
|
+
@@adapter ||= Kajian::Makro.adapter
|
14
|
+
end
|
15
|
+
|
16
|
+
def lihat *sumber_sumber
|
17
|
+
sumber_sumber = [:semua] if sumber_sumber.empty?
|
18
|
+
if sumber_sumber.length == 1
|
19
|
+
if sumber_sumber.first == :semua
|
20
|
+
raise TidakAdaAdapter unless Kajian.adapter
|
21
|
+
Kajian::KoleksiAdapter.new(Kajian.adapter)
|
22
|
+
else
|
23
|
+
s = sumber_sumber.first
|
24
|
+
Kajian::Adapter.new(s)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
Kajian::KoleksiAdapter.new(sumber_sumber)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'kajian/fungsi_bantu'
|
2
|
+
|
3
|
+
module Kajian
|
4
|
+
class Adapter
|
5
|
+
include FungsiBantu
|
6
|
+
|
7
|
+
def initialize(sumber)
|
8
|
+
if sumber.kind_of?(Class)
|
9
|
+
@kelas_sumber = sumber
|
10
|
+
@simbol_sumber = adapter_ke_simbol(sumber)
|
11
|
+
elsif sumber.kind_of?(String) or sumber.kind_of?(Symbol)
|
12
|
+
@kelas_sumber = simbol_ke_adapter(sumber)
|
13
|
+
@simbol_sumber = sumber.to_sym
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def semua
|
18
|
+
{@simbol_sumber => @kelas_sumber.dokumen}
|
19
|
+
end
|
20
|
+
|
21
|
+
def [](*daerah_daerah)
|
22
|
+
{@simbol_sumber => @kelas_sumber.dokumen(*daerah_daerah)}
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(m)
|
26
|
+
self[m]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
{
|
2
|
+
"aceh": "/aceh",
|
3
|
+
"bali": "/bali",
|
4
|
+
"balikpapan": "/balikpapan",
|
5
|
+
"barabai": "/barabai",
|
6
|
+
"bandung": "/bandung",
|
7
|
+
"banten": "/banten",
|
8
|
+
"batam": "/batam",
|
9
|
+
"bekasi": "/bekasi",
|
10
|
+
"bogor": "/bogor",
|
11
|
+
"bojonegoro": "/bojonegoro",
|
12
|
+
"boyolali": "/boyolali",
|
13
|
+
"cilacap": "/cilacap",
|
14
|
+
"cilegon": "/cilegon",
|
15
|
+
"denpasar": "/denpasar",
|
16
|
+
"depok": "/depok",
|
17
|
+
"garut": "/garut",
|
18
|
+
"gorontalo": "/gorontalo",
|
19
|
+
"indramayu": "/indramayu",
|
20
|
+
"jakarta": "/jakarta",
|
21
|
+
"jambi": "/jambi",
|
22
|
+
"jayapura": "/jayapura",
|
23
|
+
"kampar": "/kampar",
|
24
|
+
"karawang": "/karawang",
|
25
|
+
"kebumen": "/kebumen",
|
26
|
+
"kediri": "/kediri",
|
27
|
+
"kutai_kartanegara": "/kutai-kartanegara",
|
28
|
+
"madiun": "/madiun",
|
29
|
+
"magelang": "/magelang",
|
30
|
+
"makassar": "/makassar",
|
31
|
+
"malang": "/malang",
|
32
|
+
"medan": "/medan",
|
33
|
+
"manokwari": "/manokwari",
|
34
|
+
"palangkaraya": "/palangkaraya",
|
35
|
+
"pamulang": "/pamulang",
|
36
|
+
"pasuruan": "/pasuruan",
|
37
|
+
"pekalongan": "/pekalongan",
|
38
|
+
"pekanbaru": "/pekanbaru",
|
39
|
+
"pemalang": "/pemalang",
|
40
|
+
"ponorogo": "/ponorogo",
|
41
|
+
"salatiga": "/salatiga",
|
42
|
+
"samarinda": "/samarinda",
|
43
|
+
"sangatta": "/sangatta",
|
44
|
+
"semarang": "/semarang",
|
45
|
+
"sidoarjo": "/sidoarjo",
|
46
|
+
"solo": "/solo",
|
47
|
+
"sukoharjo": "/sukoharjo",
|
48
|
+
"sumedang": "/sumedang",
|
49
|
+
"surabaya": "/surabaya",
|
50
|
+
"surakarta": "/surakarta",
|
51
|
+
"tangerang": "/tangerang",
|
52
|
+
"tarakan": "/tarakan",
|
53
|
+
"tangerang_selatan": "/tangerang-selatan",
|
54
|
+
"yogyakarta": "/yogyakarta"
|
55
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'kajian/makro'
|
2
|
+
|
3
|
+
module Kajian
|
4
|
+
class Adapter
|
5
|
+
class JadwalKajian
|
6
|
+
extend Kajian::Makro
|
7
|
+
|
8
|
+
@url = 'http://jadwalkajian.com'
|
9
|
+
|
10
|
+
@direktori_master = json_ke_hash("#{simbol}.json")
|
11
|
+
|
12
|
+
# buang_direktori(
|
13
|
+
# :aceh, :bali, :balikpapan, :barabai, :bandung, :banten, :batam, :bojonegoro,
|
14
|
+
# :boyolali, :cilacap, :cilegon, :denpasar, :garut, :gorontalo, :indramayu,
|
15
|
+
# :jayapura, :kampar, :karawang, :kebumen, :kediri, :kutai_kartanegara,
|
16
|
+
# :madiun, :magelang, :makassar, :malang, :medan, :manokwari, :palangkaraya,
|
17
|
+
# :pamulang, :pasuruan, :pekalongan, :pemalang, :ponorogo, :salatiga,
|
18
|
+
# :samarinda, :sangatta, :semarang, :sidoarjo, :solo, :sukoharjo, :sumedang,
|
19
|
+
# :surabaya, :surakarta, :tarakan, :yogyakarta
|
20
|
+
# )
|
21
|
+
|
22
|
+
# pakai_direktori(:bekasi, :jakarta)
|
23
|
+
|
24
|
+
blok(css: 'div.eventon_list_event.event')
|
25
|
+
|
26
|
+
tema(css: 'span.evcal_event_title')
|
27
|
+
|
28
|
+
penceramah(css: 'span.evcal_event_subtitle', substitusi: {/dr\.?/ => 'Dr.'})
|
29
|
+
|
30
|
+
tempat do |blok|
|
31
|
+
blok.css('div.evo_location').map do |lokasi|
|
32
|
+
lokasi.css('p').map(&:text).join("\n")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
tanggal do |blok|
|
37
|
+
"#{blok.css('span.evcal_cblock .evo_date span.start').first.text.to_i} " +
|
38
|
+
"#{blok.css('span.evcal_cblock').first["data-smon"]}"
|
39
|
+
end
|
40
|
+
|
41
|
+
waktu(css: 'div.evo_time p', hilangkan: /^\(.*\)\s+/)
|
42
|
+
|
43
|
+
gambar do |blok|
|
44
|
+
blok.css('div.evo_metarow_locImg').map do |img|
|
45
|
+
img.attributes.values[1].value[/(?<=url\().*(?=\))/]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Kajian
|
2
|
+
module FungsiBantu
|
3
|
+
# Konversi dari kelas adapter ke simbol.
|
4
|
+
# Misal:
|
5
|
+
# Kajian::Adapter::JadwalKajian ke :jadwal_kajian
|
6
|
+
def adapter_ke_simbol(kelas_adapter)
|
7
|
+
kelas_adapter.name
|
8
|
+
.sub(/(\w+::)+/, '')
|
9
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
10
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
11
|
+
.tr("-", "_")
|
12
|
+
.downcase
|
13
|
+
.to_sym
|
14
|
+
end
|
15
|
+
|
16
|
+
# Konversi dari simbol ke kelas adapter.
|
17
|
+
# Misal:
|
18
|
+
# :jadwal_kajian ke Kajian::Adapter::JadwalKajian
|
19
|
+
def simbol_ke_adapter(simbol)
|
20
|
+
nama_adapter = simbol.to_s
|
21
|
+
.sub(/^[a-z\d]*/) { |match| match.capitalize }
|
22
|
+
.gsub!(/(?:_)([a-z\d]*)/i) {"#{$1.capitalize}"}
|
23
|
+
Kernel.const_get("Kajian::Adapter::#{nama_adapter}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'kajian/adapter'
|
2
|
+
|
3
|
+
module Kajian
|
4
|
+
class KoleksiAdapter
|
5
|
+
def initialize(sumber_sumber)
|
6
|
+
@adapter_adapter = sumber_sumber
|
7
|
+
end
|
8
|
+
|
9
|
+
def semua
|
10
|
+
koleksi = {}
|
11
|
+
@adapter_adapter.map do |adapter|
|
12
|
+
koleksi = koleksi.merge(Kajian::Adapter.new(adapter).semua)
|
13
|
+
end
|
14
|
+
koleksi
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](*daerah_daerah)
|
18
|
+
koleksi = {}
|
19
|
+
@adapter_adapter.map do |adapter|
|
20
|
+
koleksi = koleksi.merge(Kajian::Adapter.new(adapter)[*daerah_daerah])
|
21
|
+
end
|
22
|
+
koleksi
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(m)
|
26
|
+
self[m]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/kajian/makro.rb
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
module Kajian
|
2
|
+
KesalahanDaerah = Class.new(StandardError)
|
3
|
+
|
4
|
+
module Makro
|
5
|
+
require 'kajian/fungsi_bantu'
|
6
|
+
require 'open-uri'
|
7
|
+
require 'nokogiri'
|
8
|
+
require 'json'
|
9
|
+
require 'thread'
|
10
|
+
|
11
|
+
KOLOM = %i[tema penceramah tempat tanggal waktu gambar]
|
12
|
+
BULAN = {
|
13
|
+
"januari" => "january",
|
14
|
+
"februari" => "february",
|
15
|
+
"pebruari" => "february",
|
16
|
+
"maret" => "march",
|
17
|
+
"mei" => "may",
|
18
|
+
"juni" => "june",
|
19
|
+
"juli" => "july",
|
20
|
+
"agustus" => "august",
|
21
|
+
"oktober" => "october",
|
22
|
+
"desember" => "december",
|
23
|
+
}
|
24
|
+
|
25
|
+
extend FungsiBantu
|
26
|
+
|
27
|
+
@@adapter = []
|
28
|
+
|
29
|
+
class << self
|
30
|
+
def extended(adapter)
|
31
|
+
@@adapter << adapter
|
32
|
+
adapter.simbol = adapter_ke_simbol(adapter)
|
33
|
+
end
|
34
|
+
|
35
|
+
def adapter
|
36
|
+
@@adapter
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_accessor :simbol, *KOLOM.map {|k| "proc_#{k}"}
|
41
|
+
attr_reader :url, :direktori_master, :direktori_salinan, *KOLOM
|
42
|
+
attr_writer :proc_blok,
|
43
|
+
|
44
|
+
def dokumen *daerah_daerah
|
45
|
+
set_direktori!
|
46
|
+
@buang_direktori ||= []
|
47
|
+
@buang_direktori.each {|daerah| direktori_salinan.delete(daerah)}
|
48
|
+
unless daerah_daerah.empty?
|
49
|
+
daerah_daerah = daerah_daerah.map(&:to_sym)
|
50
|
+
daerah_daerah.each do |daerah|
|
51
|
+
raise Kajian::KesalahanDaerah, "daerah '#{daerah}' tidak ditemukan" \
|
52
|
+
unless direktori_salinan.has_key?(daerah)
|
53
|
+
end
|
54
|
+
direktori_salinan.keep_if{|k,_| daerah_daerah.include?(k)}
|
55
|
+
end
|
56
|
+
|
57
|
+
jadwal = []
|
58
|
+
direktori_salinan.to_a.each_slice(10) do |slice|
|
59
|
+
slice.map do |daerah, dir|
|
60
|
+
Thread.new do
|
61
|
+
jadwal << [daerah, @proc_blok.(daerah, dir)] rescue [daerah, []]
|
62
|
+
end
|
63
|
+
end.map(&:join)
|
64
|
+
end
|
65
|
+
jadwal.to_h
|
66
|
+
end
|
67
|
+
|
68
|
+
def json_ke_hash(file_name = "#{simbol}.json")
|
69
|
+
JSON(
|
70
|
+
File.read(File.join(File.dirname(caller[0][/^.*\.rb/]), file_name)),
|
71
|
+
symbolize_names: true
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_direktori!
|
76
|
+
@direktori_salinan = direktori_master.dup
|
77
|
+
end
|
78
|
+
|
79
|
+
def buang_direktori(*args)
|
80
|
+
set_direktori!
|
81
|
+
@pakai_direktori = direktori_master.keys - args.map(&:to_sym)
|
82
|
+
@buang_direktori = args
|
83
|
+
end
|
84
|
+
|
85
|
+
def pakai_direktori(*args)
|
86
|
+
set_direktori!
|
87
|
+
@buang_direktori = direktori_master.keys - args.map(&:to_sym)
|
88
|
+
@pakai_direktori = args.map(&:to_sym)
|
89
|
+
end
|
90
|
+
|
91
|
+
def blok(filter_blok)
|
92
|
+
@blok = if block_given?
|
93
|
+
proc {|laman| yield(laman)}
|
94
|
+
elsif filter_blok
|
95
|
+
filter_blok
|
96
|
+
end
|
97
|
+
|
98
|
+
@proc_blok = proc do |daerah, dir|
|
99
|
+
if instance_variable_get("@laman_#{daerah}").nil?
|
100
|
+
laman = Nokogiri::HTML(open(File.join(self.url, dir)))
|
101
|
+
instance_variable_set("@laman_#{daerah}", laman)
|
102
|
+
end
|
103
|
+
|
104
|
+
laman ||= instance_variable_get("@laman_#{daerah}")
|
105
|
+
|
106
|
+
if @blok.kind_of? Proc
|
107
|
+
@blok.(laman)
|
108
|
+
elsif filter_blok
|
109
|
+
laman.public_send(*filter_blok.to_a.first)
|
110
|
+
end.map do |b|
|
111
|
+
kajian = {}
|
112
|
+
KOLOM.each do |k|
|
113
|
+
konten = self.public_send("proc_#{k}").(b) rescue nil
|
114
|
+
kajian[k] = konten.kind_of?(Array) ? (k == :penceramah ? konten : konten.first) : konten
|
115
|
+
end
|
116
|
+
kajian
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
KOLOM.each do |k|
|
122
|
+
define_method k do |filter = {}, &block|
|
123
|
+
nilai_k = if block
|
124
|
+
proc {|blok| block.(blok)}
|
125
|
+
elsif filter[:css]
|
126
|
+
Hash[*filter.assoc(:css)]
|
127
|
+
elsif filter[:xpath]
|
128
|
+
Hash[*filter.assoc(:xpath)]
|
129
|
+
end
|
130
|
+
|
131
|
+
instance_variable_set("@#{k}", nilai_k)
|
132
|
+
|
133
|
+
proc_k = proc do |blok|
|
134
|
+
teks_awal = if instance_variable_get("@#{k}").kind_of? Proc
|
135
|
+
instance_variable_get("@#{k}").(blok)
|
136
|
+
elsif nilai_k
|
137
|
+
konten = blok.public_send(*nilai_k.to_a.first)
|
138
|
+
konten = if k == :gambar
|
139
|
+
konten.map {|img| img["src"]}
|
140
|
+
else
|
141
|
+
konten.map(&:text)
|
142
|
+
end
|
143
|
+
k == :penceramah ? konten : konten.first
|
144
|
+
end
|
145
|
+
|
146
|
+
if k == :penceramah
|
147
|
+
teks_awal.map do |teks|
|
148
|
+
teks_bersih = bersihkan(teks, filter[:hilangkan], k)
|
149
|
+
teks_sub = substitusi(teks_bersih, filter[:substitusi])
|
150
|
+
konversi(teks_sub, filter[:parser])
|
151
|
+
end
|
152
|
+
else
|
153
|
+
teks_bersih = bersihkan(teks_awal, filter[:hilangkan], k)
|
154
|
+
teks_sub = substitusi(teks_bersih, filter[:substitusi])
|
155
|
+
filter[:parser] ||= Date if k == :tanggal
|
156
|
+
konversi(teks_sub, filter[:parser])
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
self.public_send("proc_#{k}=", proc_k)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
def bersihkan(teks, harus_hilang, nama_kolom)
|
166
|
+
teks.gsub!(harus_hilang, '') if harus_hilang
|
167
|
+
if nama_kolom == :tema
|
168
|
+
teks.sub(/\s+((B|b)ersama (Usta(d)?(z)?(ah)?)? .*)?$/, '')
|
169
|
+
elsif nama_kolom == :penceramah
|
170
|
+
teks.sub(/^(((A|a)l(\-?|\s+))?(U|u)stad?z?(ah)?)\s+/, '')
|
171
|
+
elsif nama_kolom == :tanggal
|
172
|
+
BULAN.each do |asal_kata, terjemahan|
|
173
|
+
teks.sub!(asal_kata, terjemahan)
|
174
|
+
end
|
175
|
+
teks
|
176
|
+
else
|
177
|
+
teks
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def substitusi(teks, sub_hash)
|
182
|
+
sub_hash ? teks.gsub(*sub_hash.to_a.first) : teks
|
183
|
+
end
|
184
|
+
|
185
|
+
def konversi(teks, parser)
|
186
|
+
parser ? parser.parse(teks) : teks
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kajian
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adrian Setyadi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Pustaka ruby untuk mengekstrak data acara kajian Islam dari berbagai
|
14
|
+
situs di Indonesia. Dengan menggunakan DSL (Domain Specific Language), mudah untuk
|
15
|
+
menambahkan situs-situs lain untuk diekstrak data acara kajiannya.
|
16
|
+
email:
|
17
|
+
- adrian@setyadi.pro
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ".gitignore"
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- bin/console
|
28
|
+
- bin/setup
|
29
|
+
- kajian.gemspec
|
30
|
+
- lib/kajian.rb
|
31
|
+
- lib/kajian/adapter.rb
|
32
|
+
- lib/kajian/adapter/jadwal_kajian.json
|
33
|
+
- lib/kajian/adapter/jadwal_kajian.rb
|
34
|
+
- lib/kajian/fungsi_bantu.rb
|
35
|
+
- lib/kajian/koleksi_adapter.rb
|
36
|
+
- lib/kajian/makro.rb
|
37
|
+
- lib/kajian/version.rb
|
38
|
+
homepage: https://github.com/styd/kajian
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.5.2
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Pustaka ruby untuk mengekstrak data acara kajian Islam dari berbagai situs
|
62
|
+
di Indonesia.
|
63
|
+
test_files: []
|