Class: MemberReminder::MemberBank

Inherits:
Object
  • Object
show all
Includes:
DingTalk
Defined in:
lib/member_reminder.rb,
lib/member_reminder/member_bank.rb

Defined Under Namespace

Classes: Member, Team

Constant Summary collapse

DEFAULT_PATH =
'http://git.2dfire.net/ios/ci-yaml-shell/raw/master/boss_keeper_members.yml'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DingTalk

#post_markdown

Constructor Details

#initialize(path = DEFAULT_PATH) ⇒ MemberBank

Returns a new instance of MemberBank.



25
26
27
28
# File 'lib/member_reminder/member_bank.rb', line 25

def initialize(path = DEFAULT_PATH)
  file = open(path || DEFAULT_PATH)
  @member_yaml = YAML.load(file.read)    
end

Instance Attribute Details

#member_yamlObject (readonly)

Returns the value of attribute member_yaml.



23
24
25
# File 'lib/member_reminder/member_bank.rb', line 23

def member_yaml
  @member_yaml
end

Instance Method Details

#member_of_authors(authors) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/member_reminder/member_bank.rb', line 30

def member_of_authors(authors)
  member = authors.keys.map do |name|
    members.find do |member|
      (Array(member.name) + Array(member.alias_names)).map(&:pinyin).include?(name.pinyin.downcase)
    end
  end.compact.first
  member
end

#member_of_spec(spec) ⇒ Object



39
40
41
# File 'lib/member_reminder/member_bank.rb', line 39

def member_of_spec(spec)
  member_of_authors(spec.authors)
end

#membersObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/member_reminder/member_bank.rb', line 43

def members
  @members ||= begin
    mobiles = @member_yaml['mobiles']
    groups = @member_yaml['groups']

    @member_yaml['members'].map do |name, alias_names|
      member = Member.new
      member.name = name
      member.alias_names = alias_names
      member.team = teams.find do |team|
        token, _ = groups.find { |token, ms| ms.include?(name) }
        team.ding_token == token
      end
      member.mobile = mobiles[name]
      member
    end
  end
end

#post(members, content) ⇒ Object



9
10
11
12
13
# File 'lib/member_reminder.rb', line 9

def post(members, content)
	members.compact.group_by { |m| m.team.ding_token }.each do |token ,ms|
		super token, content, ms.map(&:mobile)
	end
end

#teamsObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/member_reminder/member_bank.rb', line 62

def teams
  @teams ||= begin
    @member_yaml['teams'].map do |name, token|
      team = Team.new
      team.name = name
      team.ding_token = token
      team
    end
  end
end