Sha256: 82a5bf994b1d24765aeb3a8b8d767d1086db73410fd10b6d4ffcc57789a49331

Contents?: true

Size: 1.92 KB

Versions: 16

Compression:

Stored size: 1.92 KB

Contents

module Gaku
  module PersonHelper

    def gender(student)
      if student.gender.nil?
        ''
      else
        if student.gender?
          t(:"gender.male")
        else
          t(:"gender.female")
        end
      end
    end

    def name_and_ruby_for(person)
      name_elements = [
        { word: person.surname,  reading: person.surname_reading },
        { word: person.name,     reading: person.name_reading }
      ]

      name_elements.map do |element|
        content_tag :ruby do
          [
            content_tag(:rb) do
              element[:word]
            end,
            content_tag(:rp, '( '),
            content_tag(:rt) do
              element[:reading]
            end,
            content_tag(:rp, ' )'),
            unless name_elements.last == element
              ' '
            end
          ].join.html_safe
        end
      end.join.html_safe
    end

    def big_person_caption_for(person)
      content_tag :caption do
        content_tag :h2 do
          person_caption_for(person)
        end
      end
    end

    def person_caption_for(person)
      content_tag :ruby do
        concat student_names(person)
        concat content_tag(:rt) { student_names person, reading: true }
      end
    end

    def student_names(student, options = {})
      @names_preset ||= Gaku::Preset.names
      reading = options[:reading]
      return reading ? student.surname : student.names if @names_preset.blank?

      result = @names_preset.gsub(/%(\w+)/) do |name|
        case name
        when '%first' then proper_name(student, :name, reading)
        when '%middle' then proper_name(student, :middle_name, reading)
        when '%last' then proper_name(student, :surname, reading)
        end
      end
      result.gsub(/\s+/, ' ').strip
    end

    private

    def proper_name(student, attribute, reading)
      reading ? student.send(attribute.to_s + '_reading') : student.send(attribute)
    end

  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
gaku_frontend-0.3.0 app/helpers/gaku/person_helper.rb
gaku_frontend-0.3.0.pre.4 app/helpers/gaku/person_helper.rb
gaku_frontend-0.3.0.pre.3 app/helpers/gaku/person_helper.rb
gaku_frontend-0.3.0.pre.2 app/helpers/gaku/person_helper.rb
gaku_frontend-0.3.0.pre.1 app/helpers/gaku/person_helper.rb
gaku_frontend-0.3.0.pre.0 app/helpers/gaku/person_helper.rb
gaku-0.2.4 frontend/app/helpers/gaku/person_helper.rb
gaku_frontend-0.2.4 app/helpers/gaku/person_helper.rb
gaku-0.2.3 frontend/app/helpers/gaku/person_helper.rb
gaku_frontend-0.2.3 app/helpers/gaku/person_helper.rb
gaku-0.2.2 frontend/app/helpers/gaku/person_helper.rb
gaku_frontend-0.2.2 app/helpers/gaku/person_helper.rb
gaku-0.2.1 frontend/app/helpers/gaku/person_helper.rb
gaku_frontend-0.2.1 app/helpers/gaku/person_helper.rb
gaku-0.2.0 frontend/app/helpers/gaku/person_helper.rb
gaku_frontend-0.2.0 app/helpers/gaku/person_helper.rb