Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Export speakers.yml for rk.org/2015
<%= @speaker.id %>:
id: <%= @speaker.id %>
name: <%= @speaker.name %>
bio: |
<%- @speaker.bio.lines do |line| -%>
<%= line.chomp %>
<%- end -%>
github_id: <%= @speaker.github %>
twitter_id: <%= @speaker.twitter %>
avatar_url: <%= @speaker.gravatar_url %>
require 'erb'
module RubyKaigi
class Speaker
delegate :name, to: :@cfp
def initialize(cfp_speaker)
@cfp = SpeakerDecorator.new(cfp_speaker)
end
def id
github || twitter || @cfp.name.parameterize.underscore
end
def bio
@cfp.bio.encode(:universal_newline => true).gsub(/\n{2,}/, "\n")
end
def github
extract_screenname(@cfp.link_to_github)
end
def twitter
extract_screenname(@cfp.link_to_twitter)
end
def gravatar_url
"http://www.gravatar.com/avatar/#{@cfp.gravatar_hash}?s=220"
end
private
def extract_screenname(url)
url[%r|@(.+)</a>|, 1]
end
end
end
SPEAKER_YML_ERB = File.read(File.expand_path('../speakers.yml.erb', __FILE__))
SPEAKER_YML = ERB.new(SPEAKER_YML_ERB, nil, '-')
speakers_yml = ''
rk2015 = Event.find(1)
accepted_confirmed_proposals =
rk2015.proposals.includes(:session, speakers: :person)
.for_state([Proposal::State::ACCEPTED, Proposal::State::SOFT_ACCEPTED])
.select(&:confirmed?)
speakers = accepted_confirmed_proposals.map(&:speakers).flatten
.reject{|s| !s.person}.map{|s| RubyKaigi::Speaker.new(s)}
speakers.sort_by(&:name).each do |s|
@speaker = s
speakers_yml << SPEAKER_YML.result(binding)
end
puts speakers_yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment