listserv 0.0.1
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 +7 -0
- data/lib/listserv.rb +128 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 518bc83a526d4f315d21a6ab50fdcbe958dac60a
|
4
|
+
data.tar.gz: dd21634983b8ca5c36903b8138f42844ca38210c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5e152c90535f2db26fdb049042bddb8d1484bbdc01d13ed4e7fc0de5bbde6654f4c31996a7782937eb4e64f8be9a47c335f66b87bb1c1dedd0e5241162ce8b23
|
7
|
+
data.tar.gz: 446bbb5e078c02947b1a629b5d9a43d736760ec91b72338c76cbe5c0290161773c68a818ea0e88b5c46ae9a75f29a8f86e8909d687fd8b89f858acdcfd7be709
|
data/lib/listserv.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
class Listserv
|
2
|
+
|
3
|
+
# Iinitialize the class, file name optional
|
4
|
+
def initialize(*args)
|
5
|
+
if args.size < 1
|
6
|
+
@title = ''
|
7
|
+
return self
|
8
|
+
else
|
9
|
+
self.load args[0]
|
10
|
+
return self
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Load a file by name
|
15
|
+
def load(filename)
|
16
|
+
@properties = Hash.new
|
17
|
+
offset = 11
|
18
|
+
length = 100
|
19
|
+
file = filename
|
20
|
+
|
21
|
+
@title = IO.read(file, length, offset += length, mode:'rb')
|
22
|
+
@title = @title.strip[2..-1]
|
23
|
+
|
24
|
+
while line = IO.read(file, length, offset += length, mode: 'rb')
|
25
|
+
property = line.scan(/\* (\S+)= (.+)/)
|
26
|
+
hash = property.to_h
|
27
|
+
hash.each do |k, v|
|
28
|
+
if @properties[k] == nil
|
29
|
+
@properties[k] = Array.new
|
30
|
+
end
|
31
|
+
v.strip.split(',').each do |val|
|
32
|
+
@properties[k].push val
|
33
|
+
end
|
34
|
+
end
|
35
|
+
if line.include? ' PW= '
|
36
|
+
break
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
@members = Array.new
|
41
|
+
while line = IO.read(file, length, offset += length, mode: 'rb')
|
42
|
+
member_matches = line.scan(/(.{1,80})[\S]{12}\/\/\/\/ /)
|
43
|
+
if member_matches.flatten!.count > 0
|
44
|
+
member_matches.each do |m|
|
45
|
+
@members.push m.strip
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
return self
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get the Listserv's title
|
53
|
+
def title
|
54
|
+
@title
|
55
|
+
end
|
56
|
+
|
57
|
+
# Get a Hash of the Listserv's properties. This includes the members
|
58
|
+
def properties
|
59
|
+
@properties
|
60
|
+
end
|
61
|
+
|
62
|
+
# Get an Array of the Listserv's members. Full names are stripped. Lowercase emails only.
|
63
|
+
def members
|
64
|
+
get_emails @members
|
65
|
+
end
|
66
|
+
|
67
|
+
# Get the Listserv's password
|
68
|
+
def pw
|
69
|
+
@properties['PW'][0]
|
70
|
+
end
|
71
|
+
|
72
|
+
# Get the Listserv's owners in an array of email addresses
|
73
|
+
def owners
|
74
|
+
get_emails @properties['Owner']
|
75
|
+
end
|
76
|
+
|
77
|
+
# Get the Listserv's editors in an array of email addresses
|
78
|
+
def editors
|
79
|
+
get_emails @properties['Editor']
|
80
|
+
end
|
81
|
+
|
82
|
+
# Get the Listserv's moderators in an array of email addresses
|
83
|
+
def moderators
|
84
|
+
get_emails @properties['Moderator']
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def get_emails(matches)
|
91
|
+
matches.flatten! #Flattens the match array in case the original contained any arrays (it probably didn't)
|
92
|
+
matches.map! {|m| m.split(',')} #Split any elements of the match array if they are comma-delimited
|
93
|
+
matches.flatten! #Flatten the split comma-delimited elements back down so this is a 1-D array again
|
94
|
+
output = [] #The output variable
|
95
|
+
matches.each do |match|
|
96
|
+
#Find any email addresses in a match
|
97
|
+
emails = match.downcase.scan(/[a-z'0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,5}/)
|
98
|
+
emails.each do |email|
|
99
|
+
output.push email #Put those email addresses into the output variable
|
100
|
+
end
|
101
|
+
end
|
102
|
+
return output #Return a flat array of email addresses.
|
103
|
+
end
|
104
|
+
|
105
|
+
def build_settings_hash
|
106
|
+
matches = @text.scan(/\* (\S+)= (.{0,100})\*/)
|
107
|
+
@properties = Hash.new
|
108
|
+
|
109
|
+
matches.each do |m|
|
110
|
+
@properties[m[0]] = Array.new
|
111
|
+
end
|
112
|
+
|
113
|
+
matches.each do |m|
|
114
|
+
@properties[m[0]].push m[1].strip
|
115
|
+
end
|
116
|
+
return @properties
|
117
|
+
end
|
118
|
+
|
119
|
+
def read_members
|
120
|
+
matches = @text.downcase.scan(/([a-z'0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,5}).{0,80}[\S]{12}\/\/\/\/ /).flatten
|
121
|
+
@members = Array.new
|
122
|
+
matches.each do |m|
|
123
|
+
@members.push m.strip
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: listserv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benjamin J. Thompson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A gem for parsing Listserv .list files
|
14
|
+
email: ben.thompson@nd.edu
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/listserv.rb
|
20
|
+
homepage: http://rubygems.org/gems/listserv
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.5.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: A gem for parsing Listserv .list files
|
44
|
+
test_files: []
|