Class: TranscribeMe::API::Recording

Inherits:
Object
  • Object
show all
Defined in:
lib/transcribeme/api/recording.rb

Overview

representation of recording objects

Constant Summary collapse

ATTRIBUTES =

Define attributes

[:date_created, :duration, :id, :name, :status, :state]
STATUS_CODES =

Define status codes

{ 
0  => "New",
4  => "File Queued for Upload",
6  => "Error during Upload",
7  => "Empty File. Nothing to upload",
8  => "Upload in Progress",
10 => "Ready for Transcription",
20 => "Awaiting Payment",
30 => "Queued",
33 => "TempBeforeHTK",
35 => "Processing Audio",
40 => "In Progress",
50 => "Completed",
90 => "Deleted" }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recording) ⇒ Recording

Public: Initializes the Recording class

recording - Hash with attributes from SOAP response



37
38
39
40
41
42
43
# File 'lib/transcribeme/api/recording.rb', line 37

def initialize(recording)
  recording.each do |key, value|
    if ATTRIBUTES.member? key.to_sym
      self.send (key.to_s + "="), value
    end
  end
end

Class Method Details

.allObject Also known as: list, to_a

Public: recording instances as a class instance

variable

Returns the Array of recording instances



104
105
106
107
# File 'lib/transcribeme/api/recording.rb', line 104

def all
  # Assign to an empty array if nil
  @@list ||= []
end

.completedObject

Public: Gets the list of completed recordings

Returns an Array with only the recordings of status 50



143
144
145
# File 'lib/transcribeme/api/recording.rb', line 143

def completed
  list.select {|l| l[:status] == 50 }
end

.in_progressObject

Public: Gets the list of in progress recordings

Returns an Array with only the recordings of status 40



150
151
152
# File 'lib/transcribeme/api/recording.rb', line 150

def in_progress
  list.select {|l| l[:state] == 40 }
end

.inspectObject Also known as: to_s

Public: Display information about the number of recordings available

Returns a String



132
133
134
# File 'lib/transcribeme/api/recording.rb', line 132

def inspect
  "TranscribeMe::API::Recordings count=#{list.count} list=[...] "
end

.method_missing(method, *args, &block) ⇒ Object

Public: Delegate methods we don’t understand to the array

method - a String or Symbol *args - optional variable arguments &block - optional block

Example:

Recording.each do |recording|
  puts recording[:name]
end

Returns the result of the delegated method call or

raises a runtime error if the method isn't findable


185
186
187
188
189
190
191
# File 'lib/transcribeme/api/recording.rb', line 185

def method_missing(method, *args, &block)
  if list.respond_to? method.to_sym
    list.send(method.to_sym, *args, &block)
  else
    super
  end
end

.new_from_soap(recordings) ⇒ Object

Public: Returns an array of recording instances

recordings - an Array of Hashes returned from a SOAP call

Returns an Array of Recording instances



120
121
122
123
124
125
126
127
# File 'lib/transcribeme/api/recording.rb', line 120

def new_from_soap(recordings)
  # Reset the list array to be blank
  @@list = []
  recordings.map do |recording|
    @@list << self.new(recording)
  end
  self
end

.processing_audioObject

Public: Gets the list of recordings currently processing audio

Returns an Array with only the recordings of status 35



157
158
159
# File 'lib/transcribeme/api/recording.rb', line 157

def processing_audio
  list.select {|l| l[:state] == 35 }
end

.ready_for_transcriptionObject Also known as: ready

Public: Gets the list of recordings currently ready for transcription

Returns an Array with only the recordings of status 10



164
165
166
# File 'lib/transcribeme/api/recording.rb', line 164

def ready_for_transcription
  list.select {|l| l[:state] == 10 }
end

Instance Method Details

#[](key) ⇒ Object

Public: Hash-like access to the attributes

key - String or Symbol

Returns the result of that method call



50
51
52
# File 'lib/transcribeme/api/recording.rb', line 50

def [](key)
  self.send key.to_sym
end

#keysObject



54
55
56
# File 'lib/transcribeme/api/recording.rb', line 54

def keys
  ATTRIBUTES
end